Docker Hub – Pushing and Pulling Images
Docker Hub is the world's largest library of container images. It works like GitHub for code — you store your images there and share them with teammates, servers, or the world. This topic teaches you how to push your own image to Docker Hub and pull images from it.
What Docker Hub Provides
Docker Hub gives you:
- Official images — maintained by Docker and software vendors (nginx, python, mysql, redis, postgres)
- Community images — shared by developers worldwide
- Your own private and public repositories — store your custom images
- Automated builds — connect to GitHub and auto-build on every push
Creating a Docker Hub Account
Go to hub.docker.com and create a free account. Your username matters — every image you push will carry it. If your username is johndoe, your images will be named johndoe/imagename:tag.
Logging In to Docker Hub from the Terminal
docker login
Docker prompts you for your username and password. On success, you see:
Login Succeeded
Docker saves your credentials locally. You do not need to log in again until you log out.
Tagging Your Image for Docker Hub
Before pushing, your image name must include your Docker Hub username:
Correct format for Docker Hub: yourusername/imagename:tag Example — tag your existing local image: docker tag my-python-app:1.0 johndoe/my-python-app:1.0
The docker tag command does not copy the image — it just adds a new name pointing to the same image data.
Pushing Your Image to Docker Hub
docker push johndoe/my-python-app:1.0
Output: The push refers to repository [docker.io/johndoe/my-python-app] a3b4c5d6e7f8: Pushed b4c5d6e7f8g9: Pushed c5d6e7f8g9h0: Layer already exists 1.0: digest: sha256:abc123... size: 1234
Docker pushes only the layers that are not already on Docker Hub. If you are pushing an image based on python:3.11-slim, Docker knows the base layers are already on Hub and skips them. Only your app's unique layers get uploaded.
Pulling Images From Docker Hub
Pull a specific image: docker pull johndoe/my-python-app:1.0 Pull an official image: docker pull nginx:1.25 Pull always gets the latest version of a tag: docker pull nginx:latest
When you run docker run and the image is not on your machine, Docker pulls it automatically. Explicit docker pull is useful when you want to download an image in advance.
Docker Hub Image URL Structure
docker pull nginx
↓ is the same as
docker pull docker.io/library/nginx:latest
Full format:
registry / namespace / repository : tag
docker.io / library / nginx : latest
↑ ↑ ↑ ↑
Docker Hub official image name version
images
(no prefix
needed)
docker.io / johndoe / my-app : 1.0
↑ ↑ ↑ ↑
Docker Hub your your your
username repo tag
Using Private Repositories
Free Docker Hub accounts get one private repository. Team and paid accounts get unlimited private repos. A private repository requires login before anyone can pull from it. This is how companies share internal images securely.
Create a private repo: 1. Log in to hub.docker.com 2. Click "Create Repository" 3. Set visibility to "Private" 4. Push your image to it Pull from a private repo (requires login): docker login docker pull yourcompany/internal-app:2.0
Other Image Registries
Docker Hub is not the only registry. Companies often use private registries for security and speed:
Registry Command prefix ─────────────────────────────────────── Docker Hub docker.io/username/ GitHub Container Reg. ghcr.io/username/ AWS ECR 123456789.dkr.ecr.us-east-1.amazonaws.com/ Google Artifact Reg. us-docker.pkg.dev/project/repo/ Azure Container Reg. myregistry.azurecr.io/
The push and pull commands work the same way — you just change the image name prefix to match the registry address.
