Pulling and pushing to Docker Hub

Overview

Teaching: 10 min
Exercises: 15 min
Questions
  • How do I publish my own images on Docker Hub?

Objectives
  • Push an image to Docker Hub

Images on Docker Hub

Docker image on Docker Hub follow the pattern <hub-user>/<repo-name>[:<tag>], e.g.:

docker pull openmicroscopy/omero-server:5.4.0

A small number of images are official Docker images and have a hub-user library which can be omitted, e.g. these are equivalent:

docker pull centos:7
docker pull library/centos:7

There are two ways to publish an image on Docker Hub, either manually, or by setting up an automated build.

Pushing to Docker Hub

First you must give your locally built image the same name that it would be published with on Docker Hub. Rename your my-omeropy-image, replacing ometraining with your Docker Hub username:

docker tag my-omeropy-image ometraining/my-omeropy-image:0.1

You must create a repository on Docker Hub before you can push to it: https://hub.docker.com/add/repository/. Docker Hub add repository Docker Hub add repository

Login to Docker Hub:

docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: ometraining
Password:
Login Succeeded

Push the image to Docker Hub:

$ docker push ometraining/my-omeropy-image:0.1
The push refers to a repository [docker.io/ometraining/my-omeropy-image]
40d9bb63f99b: Pushed
91f63c570966: Pushed
74d0a95d2fc0: Pushed
128806d79d0a: Pushed
071366fe9ed5: Pushed
96359d46c527: Pushed
889193115614: Pushed
ee8e03e5ccba: Pushed
cf516324493c: Pushed
0.1: digest: sha256:9ac559fb2ee9b5bccfcb831d2359fe2d7f6a462ffeb66fc7840918a7dbe07d99 size: 2214

If you push was successful you should see the image listed under tags on https://hub.docker.com/r/ometraining/my-omeropy-image/tags/ (replace ometraining with your username)

The latest tag

latest is a special default tag. It is not updated automatically when you push to a tag- you must push to it separately.

You should now be able to pull someone else’s image:

docker pull some-other-user/my-omeropy-image:0.1

Automated builds

Docker Hub can optionally be linked directly to GitHub (or BitBucket) so that pushing to a GitHub repository will automatically update the Docker Hub image (Docker Hub runs docker build on its own infrastructure). This works in a similar way to how Travis CI automatically runs tests when you push to GitHub.

To do this go to the Create menu, select Create Automated Build, and follow the prompts.

Alternative Docker registries

When you pull an image there are actually 4 components: <registry.address>/<user>/<repository>:<tag>. The default registry is Docker Hub but many alternative registries are available, and you can setup your own.

Key Points

  • Use docker tag to tag an image with the Docker Hub name before pushing with docker push