1

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.

enter image description here

1
  • So it looks like when running the Container-Optimized OS does give your VM a default static image name, for me mine is klt-website-zhmg as my vm is called website. I am not sure if you can actually change this at all. Commented Nov 6, 2019 at 13:26

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.