在任何其他Linux发行版上,我可以使用shebang创建一个文件并运行shell脚本,如下所示:
$ chmod +x test.sh
$ ./test.sh Johnny
hello Johnny
Run Code Online (Sandbox Code Playgroud)
但是在谷歌云平台容器优化操作系统上,我得到了 -bash: ./test.sh: Permission denied
如果我加前缀,sh例如sh test.sh Johnny它将起作用.我怎样才能让它正常工作?
$ cat test.sh
#!/usr/bin/env sh
echo "Hello $@"
matt@rancher-4mmm /tmp/matt $ chmod +x test.sh
matt@rancher-4mmm /tmp/matt $ sh ./test.sh matt
Hello matt
matt@rancher-4mmm /tmp/matt $ ./test.sh matt
-bash: ./test.sh: Permission denied
matt@rancher-4mmm /tmp/matt $ ls -la
total 4
drwxr-xr-x 2 matt matt 60 Feb 28 20:00 .
drwxrwxrwt 14 root root 280 Feb 28 19:59 ..
-rwxr-xr-x 1 …Run Code Online (Sandbox Code Playgroud) 我需要在容器上设置ulimits。例如,docker run --ulimit memlock="-1:-1" <image>。但是,我不确定在Compute Engine上部署容器优化的VM时如何执行此操作,因为它可以处理容器的启动。
我能够使用选项--privileged,-e用于环境变量,甚至是覆盖的CMD来部署VM。如何部署为容器设置了ulimits的VM?
我创建了一个 Docker 镜像,我想使用 Terraform 在 GCP 中运行它。我已经标记并将图像推送到 GCR,如下所示:
docker tag carlspring/hello-spring-boot:1.0 eu.gcr.io/${PROJECT_ID}/carlspring/hello-spring-boot:1.0
docker push eu.gcr.io/carlspring/carlspring/hello-spring-boot:1.0
Run Code Online (Sandbox Code Playgroud)
我有以下代码:
provider "google" {
// Set this to CREDENTIALS
credentials = file("credentials.json")
// Set this to PROJECT_ID
project = "carlspring"
region = "europe-west2"
zone = "europe-west2-a"
}
resource "google_compute_network" "vpc_network" {
name = "carlspring-terraform-network"
}
resource "google_compute_instance" "docker" {
count = 1
name = "tf-docker-${count.index}"
machine_type = "f1-micro"
zone = var.zone
tags = ["docker-node"]
boot_disk {
initialize_params {
image = "carlspring/hello-spring-boot"
}
}
}
Run Code Online (Sandbox Code Playgroud)
做完之后: …
我在 Google 的 Container-Optimized OS (COS) 上运行了很长时间(并且冗长)的容器作业,最终生成了足够的日志来填充磁盘。
据我所知,在使用 COS 时没有办法旋转/限制日志文件大小。
检查正在运行的容器,它似乎将一个不断增长的文件写入/var/lib/docker/containers/(挂载在有状态分区上)并且HostConfig.LogConfig.Config是空的。
我最终不得不通过 SSH 登录并手动删除多 GB 的日志文件,以使 VM 再次运行。
我通读了https://cloud.google.com/compute/docs/containers/configuring-options-to-run-containers并且据我所知没有办法(比如说)--log-opt max-size=XX按照 Docker文档:https :
//docs.docker.com/config/containers/logging/json-file/
有没有办法通过那个标志?如果失败,是否有关于如何轮换日志/限制日志大小/避免遇到此问题的建议?
在 GCE 上使用 cos-stable 容器优化的操作系统。微型实例因此 ram 非常稀疏。尝试启用交换以防止在 docker pull 期间由于 OOM 而锁定,但无法使其工作。
我意识到大多数文件夹都是无状态的,所以我将交换文件放在 home 下:
sudo fallocate -l 1G /home/user/swapfile
sudo chmod 600 /home/user/swapfile
sudo mkswap /home/user/swapfile 结果是:
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=6e965805-2ab9-450f-aed6-577e74089dbf
但sudo swapon /home/user/swapfile给出了错误:
swapon: /home/user/swapfile: swapon failed: Invalid argument
任何想法如何在 cos 上启用交换?
谢谢
调整磁盘大小后,根分区没有占用更多可用空间。
跑步时
fdisk -l
在远程 VM 上的结果是:
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Disk /dev/sda: 64 GiB, 68719476736 bytes, 134217728 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: XXXXXX-XXXXX-XXX-XXX-XXXX
Device Start End Sectors Size Type
/dev/sda1 8704000 67108830 58404831 27.9G Microsoft basic data
/dev/sda2 …Run Code Online (Sandbox Code Playgroud) Container-Optimized OS 的 syslog 文件位于何处?我正在寻找类似的东西/var/log/syslog。我需要它的原因之一是解决 ssh 登录失败问题。
我有一个在实例组中运行的 GCP实例,并使用托管在 GCR 上的单个映像进行容器优化的操作系统。
我想将一个新图像拉到 GCP,并使用该新图像刷新实例图像。我正在构建和推送 GitHub Actions,并且可以gcloud在 CI 工作流中调用一些命令。
我想说“嘿,实例组,请再次拉取容器镜像”。这样做会很好地保持服务运行。
这样做的最佳方法应该是什么?什么完整的gcloud命令来做到这一点?