gcloud docker not working on Compute Engine VM

2/5/2017

I am trying to get docker images from Container Engine to run on a Compute Engine VM. On my laptop I can run gcloud docker pull gcr.io/projectid/image-tag

I just spun up a Debian VM on Compute Engine, but when I try to run any gcloud docker command I get ERROR: (gcloud.docker) Docker is not installed.

> gcloud --version
Google Cloud SDK 140.0.0
alpha 2017.01.17
beta 2017.01.17
bq 2.0.24
bq-nix 2.0.24
core 2017.01.17
core-nix 2017.01.17
gcloud 
gsutil 4.22
gsutil-nix 4.22

> gcloud docker --version
ERROR: (gcloud.docker) Docker is not installed.

https://cloud.google.com/sdk/gcloud/reference/docker makes it seem like gcloud docker should work.

Am I supposed to install docker on the VM before running gcloud docker?

-- emh
docker
gcloud
google-compute-engine
google-kubernetes-engine

2 Answers

4/21/2017

Per intuition i tried to install docker with sudo apt-get install docker, but I was wrong, the actual docker package name is docker.io, so I restarted the process and worked this way:

  1. Install the docker package:

sudo apt-get install docker.io

  1. Test if docker is working

sudo gcloud docker ps

  1. Pull your image from the image repository, e.g. gcr.io. If dont have a particular tag use the latest one.

sudo gcloud docker -- pull gcr.io/$PROJECT_NAME/$APPLICATION_IMAGE_NAME:latest

  1. Run your image. Remember to specify the port mapping correctly, the first port is the one will be exposed in the GCE instance and the second one is the one exposed internally by the docker container, e.g EXPOSE 8000. For instance in the following example my app is configured to work at the 8000 port but it will be accessed by the public on the default www port, the 80.

sudo docker run -d -p 80:8000 --name=$APPLICATION_IMAGE_NAME \ --restart=always gcr.io/$PROJECT_NAME/$APPLICATION_IMAGE_NAME:latest

The --restart flag will allow this container to be restarted every time the instance restarts

I hope it works for you.

-- EliuX
Source: StackOverflow

2/5/2017

Am I supposed to install docker on the VM before running gcloud docker?

Yes. The error message is telling you that Docker needs to be installed on the machine for gcloud docker to work.

You can either install docker manually on your Debian VM or you can launch a VM that has docker pre-installed onto the machine, such as the Container-Optimized OS from Google.

-- Robert Bailey
Source: StackOverflow