Skillversitas

Docker Hub

Docker Hub is Docker's cloud-based registry service for sharing and managing images.

What is Docker Hub?

Docker Hub provides:
- Public Repositories: Public images accessible to anyone
- Private Repositories: Private images for organizations
- Automated Builds: Build images from GitHub/Bitbucket
- Webhooks: Notifications when an image changes

Creating a Docker Hub Account

  1. Visit https://hub.docker.com
  2. Click "Sign Up"
  3. Fill in the required information
  4. Verify your email

Logging in to Docker Hub

# Log in to Docker Hub
docker login

# Enter your username and password
# or use an access token
docker login -u username -p password

Pushing an Image to Docker Hub

# Tag the image with the username
docker tag myapp:latest username/myapp:latest

# Push to Docker Hub
docker push username/myapp:latest

Pulling an Image from Docker Hub

# Pull an official image
docker pull nginx

# Pull an image with a specific version
docker pull nginx:1.21

# Pull an image from a specific user
docker pull username/myapp:latest

Searching for Images

# Search for images
docker search nginx

# Search for images with a filter
docker search --filter=stars=100 nginx

Official Images

Some commonly used official images:
- nginx: Web server
- postgres: PostgreSQL database
- mysql: MySQL database
- node: Node.js runtime
- python: Python runtime
- redis: Cache server

Private Repositories

# Create a private repository on Docker Hub
# then push the image
docker tag myapp:latest username/myapp:private
docker push username/myapp:private

Use Case: Deploying an Application

Case: A DevOps team wants to share an application image.

# Build the myapp application image
docker build -t myapp-system:1.0 .

# Tag for Docker Hub
docker tag myapp-system:1.0 myappdev/myapp-system:1.0

# Push to Docker Hub
docker push myappdev/myapp-system:1.0

Organizations on Docker Hub

Organization: myapp-org
├── myapp-system (public)
├── myapp-api (private)
├── myapp-frontend (public)
└── myapp-database (private)

Everyday Use Case

Case: A developer needs to pull a database image for local development.

# Pull PostgreSQL for development
docker pull postgres:15

# Run PostgreSQL
docker run -d \
  --name myapp-db \
  -e POSTGRES_PASSWORD=secret \
  -e POSTGRES_DB=myapp \
  -p 5432:5432 \
  postgres:15

Docker Hub vs Private Registry

Feature Docker Hub Private Registry
Cost Limited free tier Depends on provider
Access Public/Private Private only
Control Limited Full
Storage 1 GB free Depends on plan

Best Practices

  1. Use clear tags: app:v1.0 instead of app:latest
  2. Complete description: Describe the image contents on Docker Hub
  3. Use automated builds: For CI/CD pipelines
  4. Scan for vulnerabilities: Use Docker Hub security scanning

Use Case: CI/CD Pipeline

# .github/workflows/docker-publish.yml
name: Build and Push
on:
  push:
    branches: [main]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_TOKEN }}
      - name: Build and push
        uses: docker/build-push-action@v4
        with:
          push: true
          tags: username/myapp-app:latest

Conclusion

Docker Hub is the distribution hub for Docker images. For application teams, Docker Hub makes it easy to share images between developers and deploy to production servers.