Docker in Continuous Integration: Part 3

- By Abhijit Kini on March 08, 2017

A Docker image registry service makes it easy for developers to store, manage, distribute and deploy Docker images. Use a registry service to control the storing of your images, fully own your images distribution pipeline and integrate image storage and distribution tightly into your in-house development work flow.

This blog covers "Pushing a Docker image to a registry of your choice" scenario in the Docker in Continuous Integration (CI) series. We'll go over a simple example and look at advanced scenarios of using Docker images within CI and Continuous Delivery (CD) Pipelines.

Push a Docker image to a registry of your choice

Popular image registries such as Docker Hub, Amazon EC2 Container Registry (ECR), Google Container Registry (GCR), and Quay are natively supported on Shippable. These registries eliminate the need to operate your own container repositories, provide highly available, and scalable architecture for your images.

When to use this option

Push your Docker image to an image registry to automate and trigger deployments to your test/beta/production environments. You want to rebuild dependent images, applications and trigger the rest of your pipeline, every time your base Docker image is updated.


Sample shippable.yml:

language: node_js

  - 0.12

    image_name: abhijitkini/testimage
    image_tag: latest
    pull: true
    env: FOO=bar
    options: "-e HOME=/root"
    - echo "CI is running"
    - npm install
    - docker build -t abhijitkini/testimage:$BRANCH.$BUILD_NUMBER .
    - docker push abhijitkini/testimage:$BRANCH.$BUILD_NUMBER

    - integrationName: docker-hub
      type: docker
          - master


In this example, we'll use a custom image, prior to running CI. Next, run CI with a simple echo and install npm. Build and push the image, after CI, to Docker Hub with 'Branch' and 'Build number' as the image tag.

  1. Log in to Shippable using your GitHub credentials
  2. Skip steps 3, 4 and 5 if you have followed the example of using your own custom Docker image in the previous blog
  3. Follow along by forking this Node.js sample application (sample_nodejs), available for free on GitHub.
  4. Enable the 'sample_nodejs' project
  5. Create an integration on Shippable to your image registry (Docker Hub used in this example)
  6. Copy the values of  shippable.yml file from the above sample. Replace the following values: 
    • image_name: In the pre_ci_boot  and post_ci sections, replace abhijitkini/testimage with your docker-hub-username/docker-hub-image-repo. For Google Container Registry or Amazon EC2 Container Registry, refer our documentation
    • image_tag: In the pre_ci_boot  and post_ci sections, replace latest and $BRANCH.$BUILD_NUMBER with the tag of the image you want to use
    • pull: Set to true  for the image to be pulled from the Docker registry
    • env: Specify environment variables you want inside your build container
    • options: Enter Docker options for use in the docker run command. You can also include Home environment variable as shown, if it isn't set in your image
    • integrationName: Replace docker-hub  with the name of the Docker integration you created in Step 5
    • type: docker This value specifies it is a Docker registry integration
    • branches (optional): Skip this for your integration to be applicable to all branches. In this example, it is applicable only to the master branch
  7. Commit the shippable.yml changes, which automatically triggers a build on Shippable
  8. Shippable pulls your custom image from Docker Hub and uses it in the CI process. After CI is successfully complete, it builds and pushes the image to Docker Hub with the 'Branch' and 'Build number' as the image tags.

    Docker in Continuous Integration process

    Docker in Continuous Integration process



  • Commands included in the post_ci section are run outside the build container. This means commands used in this section are not available within your build container
  • The post_ci section is not executed if the the ci section fails

Advanced Scenarios

Use Shippable to manage Docker images through out your pipeline - From building your base Docker image as part of your CI process to using the base image as part of your Continuous Delivery work flow. Achieve this without a separate DevOps tool or writing code.

Docker in Continous Delivery process

The following sample projects showcase the use of Docker in different scenarios:


Push a Docker image to a registry of your choice for use in Continuous Delivery work flow to rebuild dependent images, apps and trigger the rest of your pipelines, every time your base image is updated. The immutable Docker image is available for use in your test, beta and production environments.

In this series, we've gone through three scenarios of using Docker images in Continuous Integration process - using an existing image, building your own image, and pushing an image to a registry of your choice. The examples showcase the CI process combined with immutable Docker images expedite delivering software changes. By using Shippable, users can manage Docker images in the entire software delivery life cycle with no additional DevOps tool or writing code.

Good luck as you use Docker and Shippable to expedite your sofware delivery work flow!


Try Shippable

Topics: Docker, continuous integration (CI), Docker Hub, CI/CD, tutorial, tips