Reputation: 501
I have a docker image running on Google Cloud Platform using the Container Optimized OS with the Deploy a container image option set.
The container image runs at start-up however I am wondering if there is away of getting the image to start with a set container name, usually done with:
Docker run -d -p 8080:80 --name myapp
I would like to do this so if I then have a start-up script it can use the set name whenever the VM is rebooted with:
docker exec -it [container_name] bash
I have tried setting the --name my app in the advanced settings options for Command, Command arguments and Environment variables but each time it did not set the docker container name, I am not sure if this is possible any advice would be helpful.
Upvotes: 1
Views: 719
Reputation: 806
You won't be able to modify this to set a specific name as suggested with the command Docker run -d -p 8080:80 --name myapp
, the reason for this is that when you enable the feature Deploy a container image the creation of the container is Google managed with no configuration from you other than the image to use.
In my case the command to created the container is not even recorded in the Serial Console logs:
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'
From my test I was able to confirm that the name of the container will be the instance name between 2 random strings klt-instance-3-uwtu
Multiple restarts of the instance show the name is always the same
Upvotes: 1