Sub topic 1
What Docker Hub Is and How Repositories Work
Prerequisites
This chapter assumes Docker is installed and running, you can use a command line, and you have built an image from a Dockerfile. You also need a Docker Hub account.
Docker Hub and Repositories
Docker Hub is a public registry for storing and distributing container images. A registry is a service that stores image data and lets clients push or pull it.
A repository is a named collection of related image versions. Your Docker Hub namespace is usually your username or organization name. For example, alice/myapp identifies the myapp repository in the alice namespace.
Reading and Writing Image Names
An image reference commonly has this form:
namespace/repository:tag
For example, alice/myapp:1.0 means:
aliceis the namespace.myappis the repository.1.0is the tag, which identifies a version or variant.
If you omit a tag, Docker uses latest. Treat latest as a movable label, not as a guaranteed newest or stable release.
Starting from a Local Image
Create a small image and build it locally:
FROM alpine:3.20
CMD ["echo", "Hello from Docker Hub"]Save this as Dockerfile, then run:
docker build -t myapp:1.0 .
docker images myappThe local name myapp:1.0 is not yet associated with your Docker Hub account. You must add a second tag containing your namespace before pushing.
Logging In from the Command Line
Authenticate the Docker CLI with your Docker Hub username:
docker login -u YOUR_USERNAMEDocker prompts for a password or access token. After successful authentication, credentials are stored by Docker's credential system.
Authentication proves who you are. It does not grant access to every repository. You also need permission to push to the namespace and repository named in the image reference.
Exercise
Why does myapp:1.0 need another tag before it can be pushed to Docker Hub?
Show answer
It lacks the Docker Hub namespace. Tag it as YOUR_USERNAME/myapp:1.0 so Docker knows which repository should receive it.