Distributing your images
There would be little point in going through all the trouble of making your analyses reproducible if you can't distribute them to others. Luckily, sharing Docker containers is extremely easy, and can be done in several ways. One of the more common ways to share Docker images is through container registries and repositories.
For example, a Docker registry is a service that stores Docker images, which could be hosted by a third party, publicly or privately. One of the most common registries is Docker Hub, which is a registry hosted by Docker itself. A repository, on the other hand, is a collection of container images with the same name but different tags, i.e. versions. For example, ubuntu:latest
or ubuntu:20.04
. Repositories are stored in registries.
Note
Remember that we now have some clashing nomenclature between Git repositories (which we covered in the Git tutorial) and container repositories, so be aware of which one you're talking about!
There are many registries out there, but here are some that might be of interest to you who are taking this course:
The most common registry is probably Docker Hub, which lets you host unlimited public images and one private image for free (after which they charge a small fee). Let's see how it's done!
-
Register for an account on Docker Hub.
-
Use
docker login -u your_dockerhub_id
to login to the Docker Hub registry. -
When you build an image, tag it with
-t your_dockerhub_id/image_name
, rather than justimage_name
. -
Once the image has been built, upload it to Docker Hub with
docker push your_dockerhub_id/image_name
. -
If another user runs
docker run your_dockerhub_id/image_name
the image will automatically be retrieved from Docker Hub. You can usedocker pull
for downloading without running.
If you want to refer to a Docker image in for example a publication, it's very important that it's the correct version of the image. You can do this by adding a tag to the name like this docker build -t your_dockerhub_id/image_name:tag_name
.
Tip
On Docker Hub it is also possible to link to your Bitbucket or GitHub account and select repositories from which you want to automatically build and distribute Docker images. The Docker Hub servers will then build an image from the Dockerfile in your Git repository and make it available for download using docker pull
. That way, you don't have to bother manually building and pushing using docker push
. The GitHub repository for this course is linked to Docker Hub and the Docker images are built automatically from Dockerfile
and Dockerfile_slim
, triggered by changes made to the GitHub repository. You can take a look at the course on Docker Hub here.
Quick recap
In this section we've learned:
- How container registries and repositories work
- How to use Docker Hub to share Docker images