Deploying Docker Containers on Compute Engine

This page describes how to deploy Docker images on Google Compute Engine virtual machine instances and managed instance groups.

You can deploy Docker containers on virtual machine (VM) instances or groups of virtual machine instances. Running Docker containers directly on Compute Engine instances allows you to:

  • Deploy software with Docker on top of an existing Compute Engine setup.
  • Use Compute Engine features like autoscaling, load balancing, and sizing recommendations for virtual machine instances.
  • Control individual virtual machine instances to manage access and security of the instance.

Run Docker containers on Compute Engine when you want to use containers for deployment only but still control and manage your application at the VM instance level. Alternatively, you can use Google Container Engine to simplify cluster management and container orchestration tasks. Google Container Engine allows you to manage everything at the container level, freeing you from having to manage the underlying virtual machine instances.

Before you begin

Alpha Limitations

During Alpha, this feature has the following limitations:

  • Deploying multi-container deployments is not supported.
  • There is no container update mechanism for virtual machine instances.
  • There is no API for this feature.

Deploying a Docker image to a single virtual machine instance

You can deploy a Docker image to a new VM instance using either the Cloud Platform Console or the gcloud command-line tool.

The following example deploys a Google-provided Nginx (gcr.io/google-containers/nginx) Docker image to a VM instance. To deploy other Docker images, specify your desired Docker image instead of gcr.io/google-containers/nginx:latest in the examples below.

Console

  1. Go to the Instance page in the Cloud Platform Console.

    Go to the Instance page

  2. Click the Create instance button to create a new instance.
  3. Under the Containers section, check Create VM instance running Docker containers.
  4. In the Container deployment form:

    1. Specify a container image: gcr.io/google-containers/nginx:latest
    2. Specify a port mapping by clicking on the Add a port button and specify the following data:

      • Port: 80
      • Target port: 80
      • Protocol: TCP
    3. Click Done to save your changes.

  5. Select Allow HTTP traffic to configure the appropriate firewall.

  6. Click Create.

gcloud

Using the gcloud command-line tool, use the instances create-from-container subcommand:

gcloud alpha compute instances create-from-container nginx-vm \
    --docker-image=gcr.io/google-containers/nginx:latest \
    --port-mappings=80:80:TCP

Deploying a Docker image to a new managed instance group

You can deploy a Docker image to a managed instance group using either the Google Cloud Platform Console or the gcloud command-line tool.

To deploy a Docker image to a new managed instance group, you must first create a specialized instance template designed for Docker images and then use that template to create your managed instance group. Follow the instructions below to create both the instance template and managed instance group.

The following example deploy a Google-provided Nginx (gcr.io/google-containers/nginx) Docker image to a managed instance group. To deploy other Docker images, specify your desired Docker image instead of gcr.io/google-containers/nginx:latest in the examples below.

Console

  1. Go to the Instance Groups page in the Cloud Platform Console.

    Go to the Instance Groups page

  2. Click the Create instance group button to create a new instance group.
  3. Under Instance template, select Create another instance template. A new page appears.
  4. Check Create an instance template running Docker containers under the Containers section. In the Container deployment form:

    1. Specify a container image: gcr.io/google-containers/nginx:latest
    2. Specify a port mapping by clicking on the Add a port button and specify the following data:

      • Port: 80
      • Target port: 80
      • Protocol: TCP
    3. Click Done to save your changes.

  5. Select Allow HTTP traffic to configure the appropriate firewall.

  6. Click Save and Continue. Continue specifying other properties for the instance group as desired.
  7. Click Create to create the instance group.

gcloud

To create a specialized instance template for Docker images, use the instance-template create-from-container subcommand:

gcloud alpha compute instance-templates create-from-container nginx-template \
    --docker-image=gcr.io/google-containers/nginx:latest \
    --port-mappings=80:80:TCP

The command creates an instance template that runs the gcr.io/google-containers/nginx image. Instance created from this template directs TCP traffic from port 80 to port 80 exposed by the container. Next, use the instance template to create a new instance group. For example:

gcloud compute instance-groups managed create nginx-group \
  --template=nginx-template \
  --size=1

Support and feedback

During the Alpha program, you can email the Alpha email list list to provide feedback or ask for support.

What's next

Send feedback about...

Compute Engine Documentation