Docker in Continuous Integration: Part 1

- By Abhijit Kini on February 21, 2017

This blog series covers three Docker in Continuous Integration (CI) scenarios. A CI process combined with immutable Docker images expedites delivering software changes. Shippable makes it easy for you to use Docker images in your CI process, without a separate DevOps tool or code. The three scenarios covered in this series are:

  1. Use an existing Docker image
  2. Build your own Docker image
  3. Push a Docker image to a registry of your choice

In this blog, I'll cover the first scenario.

Use an existing Docker image

Use an existing Docker image in your CI process with either of the two options. We'll look at each option, when to use it, steps to take and examples.

  1. Shippable's default Docker image
  2. Your own custom Docker image

Shippable's default Docker image

Shippable supports 9 languages and 14 services across 3 platforms with 50+ default Docker images to support different combinations.

When to use this option:

  • Your CI process doesn't use Docker
  • Shippable's default Docker images fulfills your CI process requirements

Steps:

Specify the language, the version (optional) and the service (optional) that you need, in the shippable.yml file. Based on your input, the platform automatically chooses the best default image for your CI process.

Sample shippable.yml:

language: node_js

node_js:
  - 0.12

build:
  ci:
    - npm install

Example:

Use this step-wise tutorial to run Continuous Integration for a simple Node.js application. This example pulls a default Node.JS Docker image for the CI process.

Your own custom Docker image

Specify your private Docker image to run your build. Shippable will start the build container from your Docker image and run the CI process.

When to use this option:

  • Override Shippable's default image with your own custom Docker image
  • Set specific options for booting up the default build container for the CI process

Sample shippable.yml:

language: node_js

node_js:
  - 0.12

build:
  pre_ci_boot:
    image_name: abhijitkini/testimage
    image_tag: latest
    pull: true
env: FOO=bar options: "-e HOME=/root" ci: - npm install integrations: hub: - integrationName: docker-hub type: docker branches: only: - master

Example:

  1. Follow along by forking this Node.js sample application (sample_nodejs), available for free on GitHub. Alternatively, follow along based on your own repo. If you have never used Shippable, take 30 mins to complete the getting started tutorial.
  2. Log in to Shippable using your GitHub credentials
  3. Enable the 'sample_nodejs' project
  4. Create an integration on Shippable to your image registry (Docker Hub used in this example)
    Docker in Continuous Integration process
  5. Modify the shippable.yml file compared to the above sample. Replace the following values:
    • image_name: 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: Replace latest with the tag of the image you want to pull
    • 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 4
    • 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
  6. Commit the shippable.yml changes, which automatically triggers a build on Shippable
  7. Shippable pulls your Docker image from Docker hub and uses it in the CI process. A successful build is shown below
    Docker in Continuous Integration process

 

Important

You can combine each option with "Push a Docker image to a registry of your choice" (Scenario three) in your CI process. We'll go over this combination of scenarios in a later post.

Conclusion

Use Shippable's default Docker images in your CI process, when you don't use Docker or the default images fulfill your requirements. Use your own custom Docker image in your CI process, when you want to override the default images or set specific options to boot the build container.

In the next blog, we'll go over scenario two - "Build your own Docker image".


Try Shippable

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