Hide
Compute Engine

Container-Optimized Google Compute Engine Images

Overview

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.

Google Compute Engine is extending its support for Docker containers. This release is a Preview release of a container-optimized OS image that includes Docker and a Kubernetes Kubelet—an open source agent to manage containers.

The container OS image includes:

  • Debian 7.
  • The Docker runtime. To learn more about Docker, visit www.docker.io.
  • An open-source metadata framework and the Kubernetes Kubelet—a lightweight agent to create and manage containers based on the metadata.

Get involved

We encourage you to be involved in the development and design of the image and the related open source projects:

Starting a bare container-vm instance

A container VM image is specified like any other Google Compute Engine image, as an argument to the --image flag of the gcloud compute instances create command:

$ gcloud compute instances create instance-name \
  --image container-vm \
  --zone us-central1-a \
  --machine-type f1-micro

You can list all available versions with:

$ gcloud compute images list --project google-containers

Once the instance is running, you can SSH into the instance and use the Docker command line tool to create and manage your containers.

Creating containers at time of instance creation

The container VM image includes the Kubernetes Kubelet - an agent that can parse a YAML-formatted list of containers and create those containers at the instance's boot time. The Kubelet also monitors the listed containers, restarting them should they fail at any time.

This manifest is passed to the --metadata-from-file flag of gcloud compute instances create as a key/value pair whose key is always google-container-manifest. The value of the pair is the relative path to a manifest.

--metadata-from-file google-container-manifest=containers.yaml

All of the containers in the group share the same network namespace; you can connect from one container to a service running on another container using localhost and the port of the service. Two containers of the same group cannot run services on the same port.

Quickstart example

The following example creates a new Compute Engine instance with a busybox container. The container responds to incoming streams on port 8080 with "hello world".

Create the manifest

Create a containers.yaml file with the following contents:

version: v1
kind: Pod
metadata:
  name: simple-echo
spec:
  containers:
    - name: simple-echo
      image: gcr.io/google_containers/busybox
      command: ['nc', '-p', '8080', '-l', '-l', '-e', 'echo', 'hello world!']
      imagePullPolicy: Always
      ports:
        - containerPort: 8080
          hostPort: 8080
          protocol: TCP
  restartPolicy: Always
  dnsPolicy: Default

Create the instance

Create your Google Compute Engine instance with the gcloud compute instances create command, and pass the manifest using the --metadata-from-file flag:

$ gcloud compute instances create containervm-test-1 \
    --image container-vm \
    --metadata-from-file google-container-manifest=containers.yaml \
    --zone us-central1-a \
    --machine-type f1-micro

Test your app

Your new instance is up and running and contains the Docker container you specified in the manifest. To test it, SSH into your instance:

$ gcloud compute ssh --zone us-central1-a containervm-test-1

To confirm that the container has been created:

me@containervm-test-1:~$ sudo docker ps
CONTAINER ID        IMAGE                   COMMAND                CREATED             STATUS              PORTS                    NAMES
eb8cfe4e7848        busybox:latest          nc -p 8080 -l -l -e    12 minutes ago      Up 12 minutes                                simple-echo
1e72de9888bb        busybox:latest          sh -c 'rm -f nap &&    12 minutes ago      Up 12 minutes       0.0.0.0:8080->8080/tcp   .net

Use netcat to query the container:

me@containervm-test-1:~$ nc localhost 8080
hello world!

More examples

The Container VM Guestbook GitHub repository contains another example of using GCE container VMs to run Docker containers. It demonstrates the deployment of a Redis database and a simple Python app to create a guestbook app with local storage.

Container manifest

The YAML file is formatted as follows:

version: v1             // Required.
kind: Pod               // Required.
metadata:               // Required.
  name: string          // Required.
spec:                   // Required.
  containers:           // Required.
    - name: string      // Required.
      image: string     // Required.
      imagePullPolicy: [Always | Never | IfNotPresent]
      command: [string]
      workingDir: string
      volumeMounts:
        - name: string
          mountPath: string
          readOnly: boolean
      ports:
        - name: string
          containerPort: int
          hostPort: int
          protocol: string
      env:
        - name: string
          value: string
  restartPolicy: [Always | Never | OnFailure]
  dnsPolicy: [Default | ClusterFirst]         // Required.
  volumes:
    - name: string
      # Either emptyDir for an empty directory
      emptyDir: {}
      # Or hostPath for a pre-existing directory on the host
      hostPath:
        path: string
Field name Value type Required? Description
version string Required The version of the manifest. Must be v1.
kind string Required The type of this object. Must be Pod.
spec object Required The spec for the pod.
metadata.name string Required The name for this pod. Must be an RFC1035 compatible value.
spec.DNSPolicy string Required Must be one of Default or ClusterFirst.
spec.containers[] list Required The list of containers to launch.
spec.containers[].name string Required A symbolic name used to create and track the container. Must be an RFC1035 compatible value (a single segment of a DNS name). All containers must have unique names.
spec.containers[].image string Required The container image to run.
spec.containers[].imagePullPolicy string Whether to pull an image from the specified registry. By default this is set to Always, meaning that a remote image is pulled from the registry every time. IfNotPresent indicates that a local image should be preferred; Never uses a local image only. This can be used to preload images for speed or as an alternative to authenticating to a private registry.
spec.containers[].command[] list of string The command line to run. If this is omitted, the container is assumed to have a command embedded in it.
spec.containers[].workingDir string The initial working directory for the command. Default is the container’s embedded working directory or else the Docker default.
spec.containers[].volumeMounts[] list Data volumes to expose into the container.
spec.containers[].volumeMounts[].name string The name of the volume to mount. This must match the name of a volume defined in volumes[].
spec.containers[].volumeMounts[].mountPath string The path at which to mount the volume inside the container. This must be an absolute path and no longer than 512 characters.
spec.containers[].volumeMounts[].readOnly boolean Whether this volume should be read-only. Default is false (read-write).
spec.containers[].ports[] list Ports to expose from the container. All of these are exposed out through the public interface of the VM.
spec.containers[].ports[].name string A symbolic name used to create and track the port. Must be an RFC1035 compatible value (a single segment of a DNS name).
spec.containers[].ports[].containerPort int The port on which the container is listening.
spec.containers[].ports[].hostPort int The port on the host which maps to the containerPort. Default is the same as containerPort.
spec.containers[].ports[].protocol string The protocol for this port. Valid options are TCP and UDP. Default is TCP.
spec.containers[].env[] list Environment variables to set before the container runs.
spec.containers[].env[].name string The name of the environment variable.
spec.containers[].env[].value string The value of the environment variable.
spec.restartPolicy object The restart policy for this pod of containers. The following values are accepted:
  • Always: If a container is terminated, Kubelet will restart that container regardless of the exit code.
  • OnFailure: If a container terminates with a non-zero exit code, Kubelet will restart that container. If a container terminates with a 0 exit status (successful termination), it will not be restarted.
  • Never: If a container is terminated, Kubelet reports the termination and reason to the master, but does not restart that container.

Default is Always.

spec.volumes[] list A list of volumes to share between containers.
spec.volumes[].name string The name of the volume. Must be an RFC1035 compatible value (a single segment of a DNS name). All volumes must have unique names. These are referenced by containers[].volumeMounts[].name.
spec.volumes[].emptyDir object The default volume source. Specifies that the volume being mounted is a temporary directory that shares the pod's lifetime. The value of emptyDir is an empty object:
emptyDir: {}
You must only specify one of volumes[].emptyDir or volumes[].hostPath.
spec.volumes[].hostPath object Specifies that the volume being mounted is an existing directory on the host machine. Requires volumes[].source.hostPath.path. You must only specify one of volumes[].emptyDir or volumes[].hostPath.
spec.volumes[].hostPath.path string The path of an existing directory on the host machine to expose to the container.

Changelog

July 17, 2015
The image has been updated to container-vm-v20150715.
Added missing metadata.name field to examples and manifest description.
July 6, 2015
Removed a reference to v1beta3 API as the current version is v1.
June 14, 2015
Updated to use v1beta3 API.
June 11, 2015

The image has been updated to container-vm-v20150611.

  • BREAKING CHANGE: This image drops support for the Kubernetes v1beta1 and v1beta2 API objects. Like container-vm-v20150505, this image still supports v1beta3, but support for v1beta3 will be dropped soon.
  • This is the first ContainerVM image shipping with the Kubernetes v1 API. You can explore the v1 objects here: http://kubernetes.io/third_party/swagger-ui/. v1beta3 objects from container-vm-v20150505 should migrate seamlessly.
January 12, 2015

The image has been updated to container-vm-v20150112.

  • Upgrade docker to 1.4.1
  • Upgrade kubelet (kubernetes agent) to 0.7.4
  • Reduced size of initramfs for faster boot.
  • Bundled docker images for kubernetes/pause and cAdvisor.
  • The "container-vm" alias automatically points to this image.
December 8, 2014

The image has been updated to container-vm-v20141208.

  • Upgrade docker to 1.3.2
  • Upgrade kubelet (kubernetes agent) to 0.5.4
  • "container-vm" image alias has been created. Specifying --image container-vm when creating an instance starts up the most recent version of the container-optimized image.
October 16, 2014

The image has been updated to container-vm-v20141016.

September 29, 2014

The image has been updated to container-vm-v20140929.

  • Upgrade bash to 4.2+dfsg-0.1+deb7u1 to fix vulnerability CVE-2014-7169.
September 25, 2014

The image has been updated to container-vm-v20140925.

  • Upgrade bash to 4.2+dfsg-0.1+deb7u1 to fix vulnerability CVE-2014-6271.
August 26, 2014

The image has been updated to container-vm-v20140826.

  • Kubelet built from Kubernetes source code, trunk head as of 2014-08-22.
  • hostPort is required to be explicitly specified if a port mapping between container port and host port is required.
  • Docker 1.2 is included.
  • nsinit is included.
  • Google Cloud SDK is included.
August 1, 2014

The image has been updated to container-vm-v20140731.

  • The new image uses Docker 1.1.2.
  • cAdvisor is started by default, listening on port 4194.
July 17, 2014

The image has been updated to container-vm-v20140710.

  • The new image uses the Kubernetes Kubelet instead of container-agent.
  • version is incremented to v1beta2.
  • containers[].env[].key becomes containers[].env[].name
  • containers[].volumeMounts[].path becomes containers[].volumeMounts[].mountPath

The v1beta1 format can still be used with the original container-vm-v20140522 image.