SyntaxStudy
Sign Up
Docker Pushing Images to Docker Hub
Docker Beginner 1 min read

Pushing Images to Docker Hub

Publishing an image to Docker Hub makes it available to any Docker host worldwide. After creating a Docker Hub account and a repository, authenticate locally with docker login, tag your image with the username/repository:tag format, and push with docker push. Docker only uploads layers not already present in the registry, so repeated pushes of the same base are fast. Organisations should use private repositories for proprietary application images and public repositories for open-source projects. Docker Hub's free tier includes one private repository; for more, cloud provider registries (Amazon ECR, Google Artifact Registry, Azure Container Registry) are better choices for production workloads because they integrate with IAM roles and avoid rate limits. Automated builds from GitHub or Bitbucket can be configured on Docker Hub so that every push to a branch builds and pushes a new image automatically. However, for production use, building images in your own CI pipeline gives you more control over the build environment, secrets handling, and tagging strategy.
Example
# Authenticate to Docker Hub
docker login
docker login -u myuser

# Use an access token (safer than password)
echo $DOCKER_HUB_TOKEN | docker login -u myuser --password-stdin

# Tag image for Docker Hub
docker tag myapp:2.1.0 myuser/myapp:2.1.0
docker tag myapp:2.1.0 myuser/myapp:latest

# Push to Docker Hub
docker push myuser/myapp:2.1.0
docker push myuser/myapp:latest
docker push myuser/myapp --all-tags

# Pull from Docker Hub on another machine
docker pull myuser/myapp:2.1.0

# Log out
docker logout

# GitHub Actions CI push snippet
# - name: Push to Docker Hub
#   run: |
#     echo "${{ secrets.DOCKER_HUB_TOKEN }}" | \
#       docker login -u "${{ secrets.DOCKER_HUB_USERNAME }}" --password-stdin
#     docker push myuser/myapp:${{ github.sha }}