Deploying Docker Containers to Instance Groups

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 instances or groups of virtual machine instances. Running Docker containers directly on Compute Engine instances rather than using Container Engine provides the following advantages, including:

  • Ability to deploy software with Docker on top of an existing Compute Engine setup.
  • Ability to take advantage of Compute Engine features like autoscaling, load balancing, and sizing recommendations for virtual machine instances.
  • Allows control over individual virtual machine instances to control access and security of the instance.

If you don't need the scheduling mechanisms provided by Google Container Engine, want full control over your instances, or just want to run Docker images on virtual machine instances, use this feature.

Before you begin

Alpha Limitations

During Alpha, this feature has the following limitations:

  • Deploying to a single virtual machine instances is only available using the gcloud command-line tool
  • Deploying multi-container deployments is only available using the gcloud command-line tool, using the --container-manifest flag.
  • There is no container update mechanism for virtual machine instances.
  • There is no API for this feature.

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.

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, replace the steps where you specify gcr.io/google-containers/nginx:latest with your desired Docker image.

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 definition, select Define new container instance.
  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. Select Allow HTTP traffic to configure the appropriate firewall.

    4. Click Save and Continue.
    5. Click Create.

gcloud

To create a specialized instance template for Docker images, run this command:

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 \
  --instance-template=nginx-template \
  --size=1

Creating a single virtual machine instance running a Docker image

You can only perform this task using gcloud.

To create virtual machine instance running gcr.io/google-containers/nginx image and exposing TCP port 80, run:

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

Deploying multiple Docker images to an instance group

You can deploy multiple Docker images on a single virtual machine instance by providing a container manifest as part of the instance template. You can only perform this task using gcloud.

To create a virtual machine instance that runs multiple containers, prepare a Kubernetes container manifest in YAML or JSON format and save it in file. For example, the following containers.yaml file specifies two Docker images to run on single virtual machine instance.

apiVersion: v1
kind: Pod
metadata:
  name: multi-container-service
spec:
  containers:
    - name: nginx-server
      image: gcr.io/google-containers/nginx:latest
      imagePullPolicy: Always
      ports:
        - containerPort: 80
          hostPort: 80
          protocol: TCP
    - name: busybox-container
      command: ['sleep']
      args: ['1000']
      image: gcr.io/google-containers/busybox:latest
      imagePullPolicy: Always

To create instance template for this manifest run:

gcloud alpha compute instance-templates create-from-container multi-container-template \
    --container-manifest=containers.yaml

To create a single instance running this manifest run:

gcloud alpha compute instances create-from-container multi-container-vm \
    --container-manifest=containers.yaml

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