Building docker images with docker-compose on Google Cloud Container Builder

When you develop your application you generally want to do a full system test where you spin up your whole application with databases and different services. That was pretty easy in CircleCI version 1 but came with limitations as running many customers containers is not a small feat. They did realize that and made their version 2 that I reviewed here, but it made so it was container native, which meant that you could not use docker-compose anymore without switching to their docker-machine version which they say is slower and that we don’t want, we want speed.

Why do you want to use docker-compose?

docker-compose is excellent at making an application easy to bring on any computer and you don’t have to think about configuring databases to be on the right ports and network and have the correct database and password. I can’t imagine a development environment anymore where you have to do that manually. So it would be a great idea to use the same commands to ensure you bring up the application the same way, both because it is simple to do but also simple to debug when something inevitable does not work.

Google Cloud Container Builder

Google has the best solution to building and storing docker images right now with their Container Builder service. It allows you to specify a list of custom commands to execute in a yaml list file. It has an easy way to define which images you want to save after a build have a successfully run.

Reasons why it is great

  • It is a 1–2–3 setup process connecting to Github.
  • You can start with just a Dockerfile and switch to the task list later called cloudbuild.yaml when you want to do more.
  • You can run stuff in parallel by defining which tasks has which dependencies
  • You can have multiple triggers on the same Github commit push.

Along with Docker multi-stage build, you will get a really steady and fast continues integration and build environment with little overhead and nothing to manage.

I explain how we do it here in this article:

Docker-compose example on Google Cloud Container Builder

Google does a lot of cool things that would normally be a little complicated, for example running docker in docker, where you have to mount the docker daemon inside the container, something that you would not be allowed to at CircleCI and not something that is beginner friendly.

First, a you have to connect the repo on Container Builder.

Then you can either choose the simple docker build command

Or switch to use cloudbuild.yaml that allows you to write your own steps with for example docker-compose

Then you simply put a cloudbuild.yaml file in the root of the repository and you can essentially write any docker-compose commands:

- name: ‘docker/compose:1.19.0’
args: [‘up’, ‘-d’]

The most basic one that just builds and brings up the containers from the docker-compose.yaml file.

You can then add another line at the bottom that tells Container Builder which containers it should push to the registry and a docker tag command to give it the correct tag with the commit SHA as docker-compose will just call it latest.

- name: 'docker/compose:1.19.0'
args: ['up', '-d']
- name: ''
args: ['tag', 'workspace_app:latest', '$PROJECT_ID/$REPO_NAME:$COMMIT_SHA']

Now you are both bringing up the project like in development and pushing the result of the build after a successful run to the Google Cloud Registry ready to be run on Kubernetes Engine 🎉

Read more about Google Cloud Container Builder here at

Have questions or want to give feedback? I will love to hear what you think or if you think there is anything that could be made easier than this!