Continuous Deployment using Docker Cloud

Written by Emil Soman on July 25, 2016; tagged under

One good thing about dockerizing all your services is the ability to choose from a plethora of orchestration tools to deploy those docker images in different ways for different needs, like:

There are so many tools out there which help you run docker containers on the cloud - Kubernetes, Rancher, Flynn and many more. If you’re just getting started with docker based deployments and wondering how to set up your first continuous deployment pipeline for your dockerized app, this blog post is for you.

PS: There are no illustrations or specific instructions on how to execute a specific step. That’s intentional because UIs change often, but the concepts should remain the same. Anyways, if you get stuck, drop a comment.

What you need:

  1. An app with a Dockerfile like this one hosted on Github (or BitBucket)
  2. A Docker Hub account
  3. Knowledge of how to write a docker-compose.yml (or readiness to learn :))

Step 1. Automated builds on Docker Hub

Login to Docker Hub, create an auto-building docker repository by clicking on “Create” > “Create Automated Build”. Finish the steps by following instructions or follow this official documentation if you get stuck. What you need to ensure is that you have set up the automated deployment of your production ready branch and given it a tag like latest in Docker Hub. We’ll use this tag name later.

Step 2. Set up your node

Now log in to Docker Cloud, a tool for running docker containers on nodes - either on a cloud provider or your own servers. Follow your gut or this guide until you are ready with a node running Docker Cloud agent.

Step 3. Create a stack

Once you have set up your node, you can proceed to create a “stack”. A stack is a collection of services which run together to make your application work. Click on “Stacks” and click “Create”. This will open a text editor where you can write something called a “Stackfile”.

Step 4. Write a Stackfile for your application

A Stackfile is a YAML file that specifies the configurations for the docker containers that are part of your stack. If you have ever written a docker-compose.yml file, you should feel right at home. If you have no idea what I’m talking about, read this official documentation. Here’s an example Stackfile:

  image: 'postgres:9.4'
    - POSTGRES_USER=user
  image: 'codemancers/mywebapp:latest'
  autoredeploy: true
    - POSTGRES_USER=user
    - db
    - '3000:3000'
    - '/home/user/cache:/workspace/cache'

The above Stackfile will start two containers: a “db” container and a “mywebapp” container. A quick walkthrough:

Step 5. Deploy!

Once you have a Stackfile, paste it into the text editor you saw in step 3 and click the button to save and deploy. You can access the deployment logs for the stack by clicking on the event name under “Timeline”.


To recap, this is how the continuous deployment pipeline works:

  1. You push code to Github
  2. Github triggers docker image build on Docker Hub
  3. Docker Hub triggers redeployment of containers started from the docker image on Docker Cloud

PS: For those of you who reached this far, thanks for reading. I’ll make you an offer you can’t refuse. Get in touch with us and I’ll help you set up a kickass dev-to-prod workflow using chatbots and docker that allows you to test feature branches on disposable staging environments. This is free for the first 10 requests I get (sorry, I have only so much time for doing things for free :)).

I hope that helped. Now, dockerize all the things!