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.
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: - echo "CI is running" - npm install post-ci: - docker build -t abhijitkini/testimage:$BRANCH.$BUILD_NUMBER . - docker push abhijitkini/testimage:$BRANCH.$BUILD_NUMBER integrations: hub: - integrationName: docker-hub type: docker branches: only: - 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.
- Log in to Shippable using your GitHub credentials
- Skip steps 3, 4 and 5 if you have followed the example of using your own custom Docker image in the previous blog
- Follow along by forking this Node.js sample application (sample_nodejs), available for free on GitHub.
- Enable the 'sample_nodejs' project
- Create an integration on Shippable to your image registry (Docker Hub used in this example)
- Copy the values of
shippable.ymlfile from the above sample. Replace the following values:
image_name: In the
abhijitkini/testimagewith your docker-hub-username/docker-hub-image-repo. For Google Container Registry or Amazon EC2 Container Registry, refer our documentation
image_tag: In the
$BRANCH.$BUILD_NUMBERwith the tag of the image you want to use
pull: Set to
truefor 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 runcommand. You can also include Home environment variable as shown, if it isn't set in your image
docker-hubwith the name of the Docker integration you created in Step 5
dockerThis 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
- Commit the
shippable.ymlchanges, which automatically triggers a build on Shippable
- 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.
- Commands included in the
post_cisection are run outside the build container. This means commands used in this section are not available within your build container
post_cisection is not executed if the the
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.
The following sample projects showcase the use of Docker in different scenarios:
- A Node JS application with unit tests and coverage reports using Mocha and Istanbul. Once the CI completes, a Docker image is built and pushed to:
- A Node JS application which builds a custom Docker image before CI, runs CI tests that generate artifacts and pushes the custom built Docker container with CI artifacts to Docker Hub
- A Node JS application that builds a Docker image, pushes the image to Docker Hub after CI completes. When there's a change in the image on Docker Hub, it is deployed to Kubernetes
- Shippable Pipelines for a Node JS app with unit tests and coverage reports using Mocha and Istanbul. A Docker image is built and pushed to an Image . The image is automatically deployed to a TEST environment and manually deployed to a PRODUCTION environment using a Container service:
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!
- Sample projects from Shippable covering different scenarios
- Tutorials for Continuous Integration and Continuous Delivery pipelines
- Docker documentation