Docker Containers – Part 2 Storing and Distributing Docker Images

Docker Containers – Part 1 Introduction and Deployment
July 7, 2016

While creating and managing Docker Containers, Docker Images play an important role. Docker Images are base of containers that can help you in rapid provisioning of Docker Containers either for base containers or custom containers with your own applications.

In continuation to our previous article where we introduced Docker Containers and discussed about installing Docker Container on cloud. We have talked about packaging your application into Docker Image. Now let’s discuss about the different options available to store and distribute your Docker Images for your different requirements.

For storing and distributing Docker Images, Docker allows you to create centralized store from where you can pull and push your Docker images anytime. This storage either can be configured locally on Docker host or on the cloud.

Docker Rregistry

Docker Registry is a server side application that allows you to store and distribute Docker Images. Docker Registry provides stateless storage option to store Docker images with flexibility to scale up and down to meet your ever changing requirements. The Registry is an open source, under the permissive Apache license.

Docker Registry provides you better control to manage where your Docker images are being stored. Apart from storing Docker Images, Docker Registry offers content delivery system where you can manage your own Docker image distribution pipeline.

Let’s have a glance how you can start using your Docker Registry. You can deploy Docker Registry Server for two different use cases, mentioned below:

Docker Registry Server on local host

Before deploying Docker Registry, ensure you must have Docker version 1.6.0 or higher installed.

  1. Start Docker Registry on local host

docker run -d -p 5000:5000 –restart=always –name registry registry:2

  1. After successfully starting Docker Registry, you will be able to use Registry with Docker
  2. Some commands for basic operations with Docker Registry
    1. Pull any Docker Image from Hub and tag it to point to your Docker Registry

docker pull ubuntu && docker tag ubuntu localhost:5000/ubuntu

  1. Push/pull Images to/from your Docker Registry

docker push localhost:5000/Ubuntu

docker pull localhost:5000/ubuntu

Docker Registry Server on Domain

To deploy Docker Registry Server on Domain, it’s recommended to use Transport Layer Security (TLS). Here are some high level steps:

  1. Stop your Docker Registry server

docker stop registry && docker rm -v registry

  1. Get a certificate from a certification authority
  2. Create a certs directory and move your certificate (crt) file and key file to the certs directory.
  3. Start Docker Registry with TLS enabled

docker run -d -p 5000:5000 –restart=always –name registry \

  -v `pwd`/certs:/certs \

  -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \

  -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \

  registry:2

  1. Some commands for basic operations with Docker Registry
    1. Pull any Docker Image from Hub and tag it to point to your Docker Registry

docker pull ubuntu

docker tag ubuntu abcd.com:5000/ubuntu

  1. Push/pull Images to/from your Docker Registry

docker push abcd.com:5000/ubuntu

docker pull abcd.com:5000/ubuntu

Docker Hub

Alternate of option for Docker Registry is Docker Hub. The Docker Hub is managed service to provide cloud-based registry services that helps in building and distributing containers for applications and services. Docker Hub offers a centralized repository that allows you to perform container image discovery, container image distribution and automation workflow across the development pipeline.

Docker Hub provides multiple features including image repositories, automated builds, webhooks and organizations. In this article we will only cover feature of image repositories as an alternate for Docker Registry for storing and distributing Docker Images. Docker Hub also allows you to integrate with GitHub and Bitbucket where you can trigger the Docker Hub in case of rebuilding repositories after changes made to the repositories.

Docker Hub’s repository feature allows you to store Docker Images, push/pull images from communities and separating official and private image libraries. You can use Docker Hub services either through Docker Command Line tool or through Docker Hub web portal. Here are some high level steps to get started with Docker Hub:

  1. Create an account for Docker Hub by following instructions mentioned at Docker Hub Account.
  2. Discover and pull images from other (public and official) repositories
  3. Some basic operations to perform on Docker Hub
    1. Creating a new repository on Docker Hub

Note: You can create private or organizational repository where access to the new repository will be available either to you only (private repository) or across departments within your organization (organizational repository).

  1. Pushing a repository image to Docker Hub
  2. Rate and comments on your own and other’s repositories

In the next part of this article series, we will talk about options available for storing and distributing Docker image.

Stay tuned!!!