在GCP上使用容器优化的OS设置Docker容器名称

时间:2019-10-29 16:26:09

标签: docker google-cloud-platform

我有一个使用Container Optimized OS在Google Cloud Platform上运行的docker映像,并且设置了Deploy a container image选项。

容器映像在启动时运行,但是我想知道是否有必要使映像以设置的容器名称开头,通常使用以下方法完成:

  

Docker运行-d -p 8080:80 --name myapp

我想这样做,因此如果我有启动脚本,则只要通过以下方式重新引导VM,它就可以使用设置名称:

  

docker exec -it [container_name] bash

我尝试在高级设置选项中为我的应用设置--name 命令,命令参数和环境变量,但是每次都没有设置Docker容器名称时,我不确定是否有任何建议会有所帮助。

enter image description here

1 个答案:

答案 0 :(得分:1)

您将无法修改它来设置命令Docker run -d -p 8080:80 --name myapp所建议的特定名称,原因是当您启用功能部署容器映像时容器的创建是由Google管理的,除了要使用的图片外,您无需进行任何配置。

就我而言,创建容器的命令甚至没有记录在串行控制台日志中:

konlet-startup[401]: 2019/11/19 15:16:43 Starting Konlet container startup agent
konlet-startup[401]: 2019/11/19 15:16:44 Downloading credentials for default VM service account from metadata server
konlet-startup[401]: 2019/11/19 15:16:44 Updating IPtables firewall rules - allowing tcp traffic on all ports
konlet-startup[401]: 2019/11/19 15:16:44 Updating IPtables firewall rules - allowing udp traffic on all ports
konlet-startup[401]: 2019/11/19 15:16:44 Updating IPtables firewall rules - allowing icmp traffic on all ports
konlet-startup[401]: 2019/11/19 15:16:44 Launching user container 'gcr.io/google-containers/busybox'
konlet-startup[401]: 2019/11/19 15:16:44 Configured container 'instance-3' will be started with name 'klt-instance-3-uwtu'.
konlet-startup[401]: 2019/11/19 15:16:44 Pulling image: 'gcr.io/google-containers/busybox'
konlet-startup[401]: 2019/11/19 15:16:44 Received ImagePull response: ({"status":"Pulling from google-containers/busybox","id":"latest"}
konlet-startup[401]: {"status":"Already exists","progressDetail":{},"id":"a3ed95caeb02"}
konlet-startup[401]: {"status":"Already exists","progressDetail":{},"id":"a3ed95caeb02"}
konlet-startup[401]: {"status":"Already exists","progressDetail":{},"id":"138cfc514ce4"}
konlet-startup[401]: {"status":"Already exists","progressDetail":{},"id":"a3ed95caeb02"}
konlet-startup[401]: {"status":"Digest: sha256:d8d3bc2c183ed2f9f10e7258f84971202325ee6011ba137112e01e30f206de67"}
konlet-startup[401]: {"status":"Status: Image is up to date for gcr.io/google-containers/busybox:latest"}
konlet-startup[401]: ).
konlet-startup[401]: 2019/11/19 15:16:44 Removing a container created by a previous run of Konlet: '/klt-instance-3-uwtu
konlet-startup[401]: 2019/11/19 15:16:45 Found 0 volume mounts in container instance-3 declaration.
konlet-startup[401]: 2019/11/19 15:16:45 Created a container with name 'klt-instance-3-uwtu'

通过测试,我能够确认容器的名称将是2个随机字符串之间的实例名称 klt-instance-3-uwtu

实例的多次重启显示名称始终相同