Publishing Docker Containers
If you've read my previous blog posts, Getting Started With Docker and Building Docker Containers, you may find yourself wondering what your options are for publishing your custom docker image. Thankfully, publishing your custom images is one of the simplest things you can do. I'll show you how. I'm going to assume you've already got Docker installed locally. If you don't have it and aren't sure how to get it, check out the older posts I linked before.
This Is How We Do It
The fastest and easiest way to get started publishing images is to make yourself a DockerHub account. Once you've done this, you'll need to log in with your Docker client.
At a command prompt, enter the following:
docker login
In return, you'll be prompted for your DockerHub username and password. Enter them to complete the login process. Once you've logged in successfully, you're ready to start publishing images.
Publishing a public docker image to your personal account is incredibly easy. First, you need to make sure your image is tagged appropriately. You'll need to prefix the container's name with your DockerHub username so that docker knows what to do. Then you can publish using docker push.
The whole process goes like this:
# tagname is optional, the default is "latest"
$ docker tag my-image my-username/my-custom-image:tagname
$ docker push my-username/my-custom-image:tagname
NOTE: tagname is optional; "latest" will be used by default.
You will see the status of your image upload. Once it's complete, head over to hub.docker.com and log in to see your published image. It's important to note that following this process will publish your image publicly. Anyone will be able to view your DockerHub profile and download your image. DockerHub does support private repositories, but only provides one free private image per account (paid accounts).
You can make the image you just uploaded private by navigating to it from your DockerHub dashboard, selecting the "Settings" tab, and clicking the "Make Private" button. Alternatively, if you'd prefer to make sure your image is private as soon as you publish it, you may create your private repository on DockerHub, before you use docker push
to publish it. Click "Create Repository" on the DockerHub dashboard (after logging in) and follow the instructions given.
Alternatives To DockerHub
DockerHub isn't the only place you can publish your Docker image artifacts online. There are a number of other image repository hosts you can use both managed and self-hosted that offer a similar feature set to that of DockerHub.
Amazon, Google, Microsoft each have a container registry offering, so if you're already using one of those clouds for hosting, you can leverage those providers' own solutions to keep your billing consolidated.
Alternatively, GitHub and GitLab users can choose to keep their container images in those services alongside their application code.
These are just a handful of the options available to you. A quick Google search will reveal even more vendors like Sloppy.io and Quay.io.
For some, whether because of personal preference or business requirements, storing images on the public internet won't be desireable. The good news is that there are options for folks who need or want to host their images within their own private networks, or simply want to maintain control of their data. Two of the most popular open-source registry hosts are Harbor and Artifactory. Harbor is a Kubernetes (Cloud Native) focused solution. It also acts as a repository for hosting Helm Charts. Artifactory by JFrog is a one-stop shop for all your build artifact storage needs. In addition to being able to manage container images and Helm Charts, it can also manage RubyGems, NPM modules, or nearly any other sort of build artifact that you'd like to publish. These self-hosted options require administration and maintenance, so they are more labor-intensive solutions, but each is a great choice if you'd like to take image hosting into your own hands.
Publishing to Other Registries
If you choose to use a registry hosted somewhere other than dockerhub, your process for publishing images will change slightly. You'll still use the same tools but when tagging your image, the instructions will be slightly different. You will need to login to your preferred provider using docker login
and you will need to provide your registry's hostname and other required metadata in your image's tag.
The process for publishing to each provider differs slightly, but here is an example using AWS Elastic Container Registry (ECR). :
$ aws ecr get-login-password --region <region> | docker login -u AWS -
-password-stdin "https://$(aws sts get-caller-identity --query
'Account' --output text).dkr.ecr.<region>.amazonaws.com"
$ docker tag my-container-image my-account-id.dkr.ecr.my-aws-
region.amazonaws.com/my-registry-name/my-container-image
$ docker push my-account-id.dkr.ecr.my-aws-region.amazonaws.com/my-registry-name/my-container-image
You'll notice that the login process is different and requires you to use awscli
to retrieve your password and pipe it into docker login, using "AWS" as your username. This is an added security measure. AWS changes your password regularly to keep your account secure. In ECR, all images are private by default, and you must create the repository before using docker push either via the AWS console or commandline interface. The logging and tagging process will differ slightly for each provider, but most provide straightforward and clear instructions for their process when you create your registry. Refer to your chosen provider's documentation for more info.
Conclusion
While Docker may be the company that introduced us to Linux container images, more and more vendors and open-source projects are getting involved in the hosting of images. You are no longer limited to using a host on the public internet or run by Docker. I hope this post has helped you understand more about all the other options available to you for image hosting.