Sub topic 1
What Docker Hub is and how repositories work
Before you push an image, you need a clear picture of where it goes. This chapter explains what Docker Hub is, how its storage is organized, and how a repository relates to the image names you type on the command line. Later chapters use this model to tag, authenticate, and push.
Prerequisites
This chapter assumes you have:
- Docker installed and running locally, so that
docker versionreports both a client and a server. - Basic command-line skills, such as running commands and reading their output.
- Some experience building an image from a Dockerfile.
- A free Docker Hub account. You can create one at hub.docker.com.
You do not need to push anything yet. This chapter is about the model behind the commands.
What a registry is
A container image is a bundle of filesystem layers plus metadata. Your local Docker engine stores images on your machine. To share an image with a server, a teammate, or a CI job, you need a place both sides can reach. That place is a registry.
A registry is a server that stores images and serves them over an HTTP API. The API follows the OCI distribution specification, so many different products speak it. Docker Hub, GitHub Container Registry, Amazon ECR, Google Artifact Registry, and a self-hosted registry all work with the same docker push and docker pull commands.
Docker Hub is the registry operated by Docker. It is also the default. When an image name does not say which registry to use, the Docker CLI assumes Docker Hub. That default is why docker pull alpine works with no server address.
Docker Hub adds a web interface and account features on top of the registry:
- Repository pages with descriptions, tag lists, and image sizes.
- User and organization accounts, with team-based permissions.
- Access tokens for scripts and CI.
- Official and verified publisher images.
- Public and private repositories.
The storage hierarchy
Docker Hub organizes images in three levels: namespace, repository, and tag.
- A namespace is the owner. It is either your username or an organization name.
- A repository is a named collection of related images inside a namespace. Typically, it holds one application or service.
- A tag is a label that points to one specific version inside a repository.
The full path reads left to right from broadest to narrowest:
docker.io / YOUR_USERNAME / myapp : 1.0
registry namespace repo tagThe diagram shows that two tags can point at the same image. A tag is a movable pointer. The image itself is identified by its digest, which you will meet again in a later chapter on layers and digests.
Repositories in practice
A repository is not a single image. It is a list of tags, and each tag points to an image. When you push YOUR_USERNAME/myapp:1.0 and later YOUR_USERNAME/myapp:1.1, both live in the one repository YOUR_USERNAME/myapp.
Some practical consequences:
- One repository per application. Put different versions of the same app in one repository as different tags. Put unrelated apps in separate repositories.
- A repository must exist before anyone can pull from it, but it does not always have to be created by hand. On Docker Hub, pushing to a repository name that does not exist yet normally creates it under your namespace, if you have permission. You can also create it first on the website, which lets you choose its visibility and add a description.
- Permissions apply at the repository level. Under an organization, teams can be given read, write, or admin access to individual repositories.
- Repositories belong to a namespace permanently. You cannot push to
someoneelse/myappunless that namespace's owner has granted you write access.
Official images and the library namespace
Some names on Docker Hub have no visible namespace, such as alpine, nginx, and postgres. These are Docker Official Images, a curated set maintained with Docker. Behind the scenes they live in a namespace called library. The CLI fills it in for you.
You can see the full name Docker resolves:
docker pull alpine:3.20
docker image inspect --format '{{.RepoTags}}' alpine:3.20The first command pulls from docker.io/library/alpine. When you pull an image by its short name, the engine expands it as follows:
| What you type | What Docker resolves it to |
|---|---|
| `alpine` | `docker.io/library/alpine:latest` |
| `alpine:3.20` | `docker.io/library/alpine:3.20` |
| `YOUR_USERNAME/myapp` | `docker.io/YOUR_USERNAME/myapp:latest` |
| `ghcr.io/org/tool:2` | `ghcr.io/org/tool:2` (a different registry) |
Two rules explain the table. If no tag is given, Docker uses latest. If the first part of the name contains a dot or a colon, or is localhost, Docker treats it as a registry host. Otherwise it treats it as a namespace on Docker Hub.
You will not be able to push to library/.... Only Docker controls that namespace. Your own images always go under your username or an organization you belong to.
Naming rules
Repository and tag names have constraints, and breaking them is a common cause of errors:
- Repository names use lowercase letters, digits, and separators such as hyphens, underscores, and periods. Uppercase letters are rejected.
- Tags can contain letters, digits, underscores, periods, and hyphens. They cannot start with a period or hyphen, and they are limited to 128 characters.
- A Docker Hub namespace is your username or an organization name. These are chosen when you create the account, and you cannot change them casually.
Because the namespace is part of every image name, a typo there points to a different owner's space, not to yours. A push to a namespace you do not own fails with an access error, not a "not found" error. Chapter 11 covers how to read these messages.
Public and private repositories
Each repository is either public or private.
- A public repository can be pulled by anyone, with or without a Docker Hub account. Only people you authorize can push.
- A private repository requires authentication for both pulling and pushing. Anyone you did not authorize sees "not found" or "access denied."
Docker Hub plans differ in how many private repositories they include, so check your plan's current limits on the Docker website. Choosing between the two is covered in its own chapter. For now, remember that visibility is a property of the repository, not of an individual tag or image.
Rate limits and anonymous access
Docker Hub limits how many pulls an anonymous client, or a free account, can make in a given period. Pushes are not the usual concern, but pulls in CI and on shared networks are. Logging in generally raises your allowance. The exact numbers change over time, so do not hard-code them in documentation or scripts. If a CI job fails with a "too many requests" message, authenticate the job first.
Seeing the model in your own account
A short walkthrough ties these ideas together. You do not push anything here.
- Sign in at hub.docker.com and open your account's repository list. It may be empty.
- Click Create repository.
- Enter the name
myapp. The namespace shown beside it is your username. - Choose a visibility and create it.
The page you land on shows the command for pushing to that repository. It uses exactly the three-part name from the hierarchy above, with YOUR_USERNAME replaced by your real namespace. The repository exists, but the Tags tab is empty until someone pushes.
Now compare what you see on the website with what is on your machine:
docker imagesThe REPOSITORY column in the output uses the same word, but locally it only means "the name part of an image reference." A local repository name such as myapp has no connection to Docker Hub until you add the namespace prefix. That mapping step is called tagging, and it is the subject of an upcoming chapter.
Common misunderstandings
- "Docker Hub is Docker." It is one registry among many. Everything you learn here carries over to other registries, with only the hostname and login differing.
- "A repository is a Git repository." A Docker Hub repository stores built images, not source code. It has no branches or commits.
- "A tag is a copy of the image." A tag is a pointer. Two tags can share the same image, which uses no extra storage.
- "Local names are global." A name like
myapp:1.0exists only on your machine. Nothing on Docker Hub can be named that way, because every Docker Hub name needs a namespace.
What comes next
Next, you will break image names into their parts and see how Docker interprets them. After that, you will start from a small local image, log in, tag it for your repository, push it, and verify the result by pulling it back.
Exercise
You run docker pull nginx:1.27 and docker pull acme/nginx:1.27. Which registry does each command contact, and which namespace does each image come from? Which of the two could you push to with a normal personal account, assuming you are not a member of the acme organization?
Show answer
Both commands contact Docker Hub (docker.io), because neither name starts with a registry host. The first resolves to docker.io/library/nginx:1.27, an Official Image in the library namespace. The second resolves to docker.io/acme/nginx:1.27, from the acme namespace. You could push to neither. Only Docker controls library, and acme accepts pushes only from members with write access.
Exercise
A teammate says, "I pushed myapp:1.0 to Docker Hub." Why is that statement incomplete, and what would a complete Docker Hub reference look like?
Show answer
A Docker Hub image needs a namespace, and myapp:1.0 has none. A bare local name like that would not reach your own repository. A complete reference includes the namespace, for example YOUR_USERNAME/myapp:1.0, which Docker expands to docker.io/YOUR_USERNAME/myapp:1.0.