Three months ago, I posted on this blog a tutorial that teaches how to deploy on Google Compute Engine a Java 8 application packaged in a Docker container.
As Docker is getting more and more traction, Google now let us deploy Docker containers on Compute Engine instances, at creation time. It leverages two things that are not new:
An new stock VM image is provided by Google. Its full path is projects/google-containers/global/images/container-vm-v20140522. It’s a bare Debian VM whose sole purpose is to start Docker containers.
Right now it doesn’t look like it’s as small as boot2docker or debian2docker. For example apt-get is installed but shouldn’t be useful since you only want to run containers. Also there are twice as many commands in the path as on a boot2docker.
When you create the instance, if you pass a yaml file that contains metadata, these metadata can be used by the VM to perform some setup work at creation time.
That’s exactly how you deploy Docker containers at creation time. You write a yaml file like this one:
- name: helloworld
command: ['java', '-jar', 'target/hello.jar']
- name: http
And you create a new instance with a command like this one:
gcloud compute instances create NAME --image projects/google-containers/global/images/container-vm-v20140522 --metadata-from-file google-container-manifest=containers.yaml --zone europe-west1-b --machine-type n1-standard-1 --tags=http-server
And once the vm is created, it will automatically pull dgageot/helloworld container from Docker Index and start the container with the given port forwarding configuration.
Of course, it’s possible to deploy many containers on the same vm. That’s the beauty of it!