Pulling Images
Overview
Teaching: 10 min
Exercises: 5 minQuestions
How are images downloaded?
How are images distinguished?
Objectives
Pull images from Docker Hub image registry
List local images
Introduce image tags
Docker Hub and Image Registries
Much like GitHub allows for web hosting and searching for code, the Docker Hub image registry allows the same for Docker images. Hosting and building of images is free for public repositories and allows for downloading images as they are needed. Additionally, through integrations with GitHub and Bitbucket, Docker Hub repositories can be linked against Git repositories so that automated builds of Dockerfiles on Docker Hub will be triggered by pushes to repositories.
While Docker Hub is maintained by Docker and is the defacto default registry for Docker images, it is not the only registry in existence. There are many registries, both private and public, in existence. For example, the GitLab software allows for a registry service to be setup alongside its Git and CI/CD management software. CERN’s GitLab instance has such a registry available. See later episodes for more information on CERN’s GitLab Docker image registry. GitHub also now provides its own container registry called GHCR, which uses the namespace https://ghcr.io
.
Pulling Images
To begin with we’re going to pull down the Docker image we’re going to be working in for the tutorial (Note: If you did all the docker pulls in the setup instructions, this image will already be on your machine. In this case, docker should notice it’s there and not attempt to re-pull it, unless the image has changed in the meantime.):
docker pull sl
# if you run into a permission error, use "sudo docker run ..." as a quick fix
# to fix this for the future, see https://docs.docker.com/install/linux/linux-postinstall/
Using default tag: latest
latest: Pulling from library/sl
be7dd8a3f6cc: Pull complete
Digest: sha256:d20a8476d2369be2f3553382c9cce22f1aace2804cf52450b9dbacc93ae88012
Status: Downloaded newer image for sl:latest
docker.io/library/sl:latest
The image names are composed of NAME[:TAG|@DIGEST]
, where the NAME
is composed of REGISTRY-URL/NAMESPACE/IMAGE
and is often referred to as a repository. Here are some things to know about specifying the image:
- Some repositories will include a
USERNAME
as part of the image name (i.e.fnallpc/fnallpc-docker
), and others, usually Docker verified content, will include only a single name (i.e.sl
). - A registry path (
REGISTRY-URL/NAMESPACE
) is similar to a URL, but does not contain a protocol specifier (https://). Docker uses the https:// protocol to communicate with a registry, unless the registry is allowed to be accessed over an insecure connection. Registry credentials are managed by docker login. If no registry path is given, the docker daemon assumes you meant to pull from Docker Hub and automatically appendsdocker.io/library
to the beginning of the image name. - If no tag is provided, Docker Engine uses the
:latest
tag as a default. - The SHA256
DIGEST
is much like a Git hash, where it allows you to pull a specific version of an image. - CERN GitLab’s repository path is
gitlab-registry.cern.ch/<username>/<repository>/<image_name>[:<tag>|@<digest>]
.
Now, let’s list the images that we have available to us locally
docker images
If you have many images and want to get information on a particular one you can apply a filter, such as the repository name
docker images sl
REPOSITORY TAG IMAGE ID CREATED SIZE
sl latest 33957a339e91 2 weeks ago 187MB
or more explicitly
docker images --filter=reference="sl"
REPOSITORY TAG IMAGE ID CREATED SIZE
sl latest 33957a339e91 2 weeks ago 187MB
You can see here that there is the TAG
field associated with the
sl
image.
Tags are way of further specifying different versions of the same image.
As an example, let’s pull the 7
release tag of the
sl image (again, if it was already pulled during setup, docker won’t attempt to re-pull it unless it’s changed since last pulled).
docker pull sl:7
docker images sl
7: Pulling from library/sl
Digest: sha256:d20a8476d2369be2f3553382c9cce22f1aace2804cf52450b9dbacc93ae88012
Status: Downloaded newer image for sl:7
docker.io/library/sl:7
REPOSITORY TAG IMAGE ID CREATED SIZE
sl 7 33957a339e91 2 weeks ago 187MB
sl latest 33957a339e91 2 weeks ago 187MB
Pulling Python
Pull the image python:3.7-slim for Python 3.7 and then list all
python
images along with thesl:7
imageSolution
docker pull python:3.7-slim docker images --filter=reference="sl" --filter=reference="python"
3.7-slim: Pulling from library/python 42c077c10790: Pull complete f63e77b7563a: Pull complete dca49bd08fde: Pull complete 51a05345c44d: Pull complete e69ebd661d90: Pull complete Digest: sha256:f61a4c6266a902630324fc10814b1109b3f91ac86dfb25fa3fa77496e62f96f5 Status: Downloaded newer image for python:3.7-slim docker.io/library/python:3.7-slim REPOSITORY TAG IMAGE ID CREATED SIZE python 3.7-slim 600bb8fe36b6 2 weeks ago 123MB sl 7 33957a339e91 2 weeks ago 187MB sl latest 33957a339e91 2 weeks ago 187MB
Key Points
Pull images with
docker pull
List images with
docker images
Image tags distinguish releases or version and are appended to the image name with a colon
The default registry is Docker Hub