liveBook · Manning

Docker Hub

As explained in Road to Kubernetes

Docker Hub is a hosted registry service for discovering, storing, and distributing container images.

Docker Hub is a hosted container registry: a place to find, store, and distribute container images. Docker uses it by default when an image is missing locally. For example, `docker run nginx` downloads the official NGINX image before starting its container. section 5.1.1

A practical path from a prebuilt image to your own:

  • Find the image you need and choose a version on its Tags tab. For Python 3.11.4, `docker pull python:3.11.4` downloads that tagged image; the same image name and tag can go in a Dockerfile’s `FROM` line. section 5.3.1
  • Build your application image, then give it a Docker Hub name in the form `<username>/<image>:<tag>`. Log in with `docker login` and upload it with `docker push <username>/<image>:<tag>`. section 5.5
  • Choose visibility deliberately. A repository created by pushing is public by default; create it before the first push if it needs to be private. section 5.5 section 5.5.1

Keep a version and a default tag

A Python application image can be built with both `codingforentrepreneurs/rk8s-py:0.0.1` and `codingforentrepreneurs/rk8s-py:latest`, then pushed to Docker Hub. An image name without a tag uses `latest` by default; the numbered tag identifies a particular iteration. section 5.5.1

Listing 5.14 Pushing our Python container image to Docker Hub
cd ~/dev/roadtok8s/py

# if you haven't already
# login to Docker Hub
docker login

# build and tag twice
docker build -f Dockerfile \
    -t codingforentrepreneurs/rk8s-py:0.0.1 \
    -t codingforentrepreneurs/rk8s-py:latest \
    .

# push a specific tag
docker push codingforentrepreneurs/rk8s-py:0.0.1

# push all tagged versions
docker push codingforentrepreneurs/rk8s-py --all-tags

Follow the complete Python example from command-line login through building with two tags and pushing either one tag or all tags. section 5.5.1

Once an image is hosted, a production Docker Compose file can name it directly. The production machine can pull the image and start its container with `docker compose pull` and `docker compose up -d`. For a private image, log in to Docker Hub on that machine first. section 7.3.3

How Road to Kubernetes covers it

How deep it goes
Walks through tag selection, login, building, pushing, visibility, and production pulls; leaves self-hosting a registry aside.
Examples
Uses official NGINX, Python, and Node.js images, then a tagged Python application image pushed to Docker Hub.
What it assumes
Introduces the registry during a first container run, then uses a Dockerfile and Docker CLI commands for publishing.
What you can do after
Operate/configure it by selecting image tags, pushing a built image, and supplying hosted images to a production deployment.
How it connects
Connects image tags and Dockerfiles to Docker Compose, GitHub Actions, and container deployment.

Also explained in

Compare how 2 books explain Docker Hub →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.