This lesson is being piloted (Beta version)

Pulling Images

Overview

Teaching: 10 min
Exercises: 5 min
Questions
  • How are images downloaded?

  • How are images distinguished?

Objectives
  • Pull images from Docker Hub image registry

  • List local images

  • Introduce image tags

Docker Hub

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.

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 which case docker should notice it’s there and not attempt to re-pull it unless it’s changed in the meantime):

docker pull matthewfeickert/intro-to-docker

#if you run into a premission error, use "sudo docker run ..." as a quick fix
# to fix this for the future, see https://docs.docker.com/install/linux/linux-postinstall/

and then 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 matthewfeickert/intro-to-docker
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
matthewfeickert/intro-to-docker   latest              cf6508749ee0        3 months ago        1.49GB

or more explicitly

docker images --filter=reference="matthewfeickert/intro-to-docker"
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
matthewfeickert/intro-to-docker   latest              cf6508749ee0        3 months ago        1.49GB

You can see here that there is the TAG field associated with the matthewfeickert/intro-to-docker image. Tags are way of further specifying different versions of the same image. As an example, let’s pull the buster release tag of the Debian 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 debian:buster
docker images debian
buster: Pulling from library/debian
<some numbers>: Pull complete
Digest: sha256:<the relevant SHA hash>
Status: Downloaded newer image for debian:buster
docker.io/library/debian:buster

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
debian              buster              00bf7fdd8baf        5 weeks ago         114MB

Pulling Python

Pull the image python3.7-slim for Python 3.7 and then list all python images along with the matthewfeickert/intro-to-docker image

Solution

docker pull python:3.7-slim
docker images --filter=reference="matthewfeickert/intro-to-docker" --filter=reference="python"
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
python                            3.7                 e440e2151380        23 hours ago        918MB
matthewfeickert/intro-to-docker   latest              cf6508749ee0        3 months ago        1.49GB

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