What's the procedure for installing and running Docker on Google Compute Engine?
-
Sadly Google has not created yet any documentation for Docker https://developers.google.com/search/results?q=docker – glarrain Feb 05 '14 at 11:31
13 Answers
Until the recent GA release of Compute Engine, running Docker was not supported on GCE (due to kernel restrictions) but with the newly announced ability to deploy and use custom kernels, that restriction is no longer intact and Docker now works great on GCE.
Thanks to proppy, the instructions for running Docker on Google Compute Engine are now documented for you here: http://docs.docker.io/en/master/installation/google/. Enjoy!

- 3,742
- 2
- 19
- 19
-
can you point to a working example where the docker container serves some content? So far even google's own example: `https://github.com/GoogleCloudPlatform/container-vm-guestbook-redis-python` doesn't work because port 80 is occupied by the Docker process on the GCE host instance and after changing the port for the app, still can't figure out why the port is not being forwarded. If you could share a todo or hello-world app being run on GCE successfully with proper port mappings, it'd be of great help. – pulkitsinghal May 01 '15 at 16:50
-
They now have a VM which has docker pre-installed now.
$ gcloud compute instances create instance-name
--image projects/google-containers/global/images/container-vm-v20140522
--zone us-central1-a
--machine-type f1-micro
https://developers.google.com/compute/docs/containers/container_vms

- 1,160
- 15
- 19
-
For posterity: this project no longer offers images. `$ gcloud compute images list --no-standard-images --project=google-containers` returns "Listed 0 items" – kkm inactive - support strike Dec 04 '19 at 10:19
A little late, but I wanted to add an answer with a more detailed workflow and links, since answers are still rather scattered:
Create a Docker image
a. Locally
b. Using Google Container Builder
Push local Docker image to Google Container Repository
docker tag <current name>:<current tag> gcr.io/<project name>/<new name>
gcloud docker -- push gcr.io/<project name>/<new name>
UPDATE
If you have upgraded to Docker client versions above 18.03, gcloud docker commands are no longer supported. Instead of the above push, use:
docker push gcr.io/<project name>/<new name>
If you have issues after upgrading, see more here.
Create a compute instance. This process actually obfuscates a number of steps. It creates a virtual machine (VM) instance using Google Compute Engine, which uses a Google-provided, container-optimized OS image. The image includes Docker and additional software responsible for starting our docker container. Our container image is then pulled from the Container Repository, and run using docker run when the VM starts. Note: you still need to use docker attach even though the container is running. It's worth pointing out only one container can be run per VM instance. Use Kubernetes to deploy multiple containers per VM (the steps are similar). Find more details on all the options in the links at the bottom of this post.
gcloud beta compute instances create-with-container <desired instance name> \ --zone <google zone> \ --container-stdin \ --container-tty \ --container-image <google repository path>:<tag> \ --container-command <command (in quotes)> \ --service-account <e-mail>
Tip You can view available gcloud projects with
gcloud projects list
SSH into the compute instance.
gcloud beta compute ssh <instance name> \ --zone <zone>
Stop or Delete the instance. If an instance is stopped, you will still be billed for resources such as static IPs and persistent disks. To avoid being billed at all, use delete the instance.
a. Stop
gcloud compute instances stop <instance name>
b. Delete
gcloud compute instances delete <instance name>
Related Links:
- More on deploying containers on VMs
- More on zones
- More create-with-container options

- 4,896
- 4
- 23
- 42
-
Instead of `docker tag` and `gcloud docker --push` I think one can instead use `gcloud container builds submit --tag gcr.io/
/ – geoidesic Apr 11 '18 at 17:38.` which will build the image and send it straight to the google repository, skipping out the docker repository steps. -
Also step 2 gives me an error: "Docker login failed", even after "docker login". I think this is due to deprecation of this command: https://cloud.google.com/sdk/gcloud/reference/docker – geoidesic Apr 11 '18 at 18:22
-
Yeah I've been working through the deprecation of gcloud docker myself this morning after updating gcloud/docker. Switching to docker-credential-gcr seems to work. More here: https://stackoverflow.com/questions/49780218/docker-credential-gcloud-not-in-system-path?noredirect=1#comment86579350_49780218 – ZaxR Apr 11 '18 at 18:37
-
@geoidesic - I updated the instructions above for Docker client versions above 18.03. Hope that helps! – ZaxR Apr 11 '18 at 21:16
As of now, for just Docker, the Container-optimized OS is certainly the way to go:
gcloud compute images list --project=cos-cloud --no-standard-images
It comes with Docker and Kubernetes preinstalled. The only thing it lacks is the Cloud SDK command-line tools. (It also lacks python3, despite Google's announce of Python 2 sunset on 2020-01-01. Well, it's still 27 days to go...)
As an additional piece of information I wanted to share, I was searching for a standard image that would offer both docker and gcloud/gsutil preinstalled (and found none, oops). I do not think I'm alone in this boat, as gcloud
is the thing you could hardly go by without on GCE¹.
My best find so far was the Ubuntu 18.04 image that came with their own (non-Debian) package manager, snap. The image comes with the Cloud SDK preinstalled, and Docker installs literally in a snap, 11 seconds on an F1 instance initial test, about 6s on an n1-standard-1. The only snag I hit was the error message that the docker authorization helper was not available; an attempt to add it with gcloud components install
failed because the SDK was installed as a snap, too. However, the helper is actually there, only not in the PATH. The following was what got me the both tools available in a single transient builder VM in the least amount of setup script runtime, starting off the supported Ubuntu 18.04 LTS image²:
snap install docker
ln -s /snap/google-cloud-sdk/current/bin/docker-credential-gcloud /usr/bin
gcloud -q auth configure-docker
¹ I needed both for a Daisy workflow imaging a disk with both artifacts from GS buckets and a couple huge, 2GB+ library images from the local gcr.io registry that were shared between the build (as cloud builder layers) and the runtime (where I had to create and extract containers to the newly built image). But that's besides the point; one may needs both tools for a multitude of possible reasons.
² Use gcloud compute images list --uri | grep ubuntu-1804
to get the most current one.

- 5,190
- 2
- 32
- 59
Google's GitHub site offers now a gce image including docker. https://github.com/GoogleCloudPlatform/cloud-sdk-docker-image

- 69
- 6
It's as easy as:
- creating a Compute Engine instance
curl https://get.docker.io | bash

- 2,496
- 1
- 22
- 13
-
3`curl https://get.docker.io` is safer. You don't ever want to to take code from insecure packets and execute it. – Beni Cherniavsky-Paskin Jan 21 '15 at 11:02
-
4Damn, google recommends to install gcloud sdk with this "pipe to bash" method. I hope your comment triggers an army of ants to fix this security issue. – lukeforehand Dec 10 '15 at 00:39
Using docker-machine
is another way to host your google compute instance with docker.
docker-machine create \
--driver google \
--google-project $PROJECT \
--google-zone asia-east1-c \
--google-machine-type f1-micro $YOUR_INSTANCE
If you want to login this machine on google cloud compute instance, just use docker-machine ssh $YOUR_INSTANCE
Refer to docker machine driver gce

- 1,272
- 1
- 12
- 25
There is now improved support for containers on GCE:
Google Compute Engine is extending its support for Docker containers. This release is an Open Preview of a container-optimized OS image that includes Docker and an open source agent to manage containers. Below, you'll find links to interact with the community interested in Docker on Google, open source repositories, and examples to get started. We look forward to hearing your feedback and seeing what you build.
Note that this is currently (as of 27 May 2014) in Open Preview:
This is an Open Preview release of containers on Virtual Machines. As a result, we may make backward-incompatible changes and it is not covered by any SLA or deprecation policy. Customers should take this into account when using this Open Preview release.

- 12,938
- 4
- 61
- 78
Running Docker on GCE instance is not supported. The instance goes down and not able to login again.
We can use the Docker image given by the GCE, to create a instance.

- 111
- 4
-
Doesn't come with gcloud installed though and the installation instructions `sudo curl https://sdk.cloud.google.com | bash` don't work on ChromiumOS: 'permission denied'. – geoidesic Apr 11 '18 at 17:44
-
@geoidesic, the instruction is (or was) incorrect, and it's kinda obvious why you got the permission error: you elevate curl, not bash. Instead, `curl .... | sudo bash` is the correct plumbing. Shell parses the pipes and runs two commands: the first is `sudo` (with the argument `curl etc.`) and the second is just `bash`. `sudo` needlessly elevates `curl`, but `bash`, which needs elevated rights, runs as your user id. – kkm inactive - support strike Aug 11 '20 at 10:34
If your google cloud virtual machine is based on ubuntu use the following command to install docker sudo apt install docker.io

- 146
- 1
- 8
You may use this link: https://cloud.google.com/cloud-build/docs/quickstart-docker#top_of_page.
The said link explains how to use Cloud Build to build a Docker image and push the image to Container Registry. You will first build the image using a Dockerfile and then build the same image using the Cloud Build's build configuration file.

- 474
- 4
- 5
Its better to get it while creating compute instance
- Go to the VM instances page.
- Click the Create instance button to create a new instance.
- Under the Container section, check Deploy container image.
- Specify a container image name under Container image and configure options to run the container if desired. For example, you can specify gcr.io/cloud-marketplace/google/nginx1:1.12 for the container image.
- Click Create.

- 11
- 2
-
1A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](//stackoverflow.com/help/deleted-answers) – FelixSFD Nov 25 '17 at 17:47
-
Installing Docker on GCP Compute Engine VMs:
This is the link to GCP documentation on the topic:
https://cloud.google.com/compute/docs/containers#installing
In it it links to the Docker install guide, you should follow the instructions depending on what type of Linux you have running in the vm.

- 4,780
- 6
- 29
- 47