๐Ÿ“ฆ (Post 4): Docker Registries: Docker Hub, Private Registry & Image Sharing!

After building beautiful containers and connecting them in networks, it's time to share your hard work. Whether you're working in a team, deploying to servers, or simply backing up your images โ€” Docker Registries are the way to store and distribute container images across systems.

๐Ÿ—‚ What is a Docker Registry?

A Docker registry is a storage and distribution system for named Docker images. It holds versions of images (tags) and allows push/pull access through Docker clients.

Common Registries:

โ˜๏ธ Docker Hub Basics

Docker Hub is like GitHub โ€” but for Docker images. It's the default registry Docker pulls from.

๐Ÿ” Logging in:

docker login

You'll be prompted for your Docker ID and password. This stores a token in ~/.docker/config.json.

๐Ÿท Tagging an Image:

Before pushing, tag it properly with your Docker Hub username:

docker tag myapp aelify/myapp:v1

โฌ†๏ธ Pushing to Docker Hub:

docker push aelify/myapp:v1

โฌ‡๏ธ Pulling from Docker Hub:

docker pull aelify/myapp:v1

๐Ÿงผ Best Practices:

๐Ÿ” Hosting Your Own Private Docker Registry

Don't want to rely on Docker Hub? You can host your own registry using the official image.

โš™๏ธ Start a Registry Container

docker run -d \
  -p 5000:5000 \
  --name registry \
  registry:2

This will start a local registry at localhost:5000.

๐Ÿ“ฆ Tag and Push to Local Registry

docker tag myapp localhost:5000/myapp
docker push localhost:5000/myapp

๐Ÿ“ฅ Pull from Local Registry

docker pull localhost:5000/myapp

๐Ÿ›ก Securing with a Domain and SSL (Advanced)

Running a private registry in production? You'll need a domain + HTTPS.

Step 1: Nginx Reverse Proxy

server {
  listen 443 ssl;
  server_name registry.mycompany.com;

  ssl_certificate /etc/nginx/ssl/fullchain.pem;
  ssl_certificate_key /etc/nginx/ssl/privkey.pem;

  location / {
    proxy_pass http://localhost:5000;
  }
}

Step 2: Docker Daemon Trust

Tell Docker to trust your registry:

// /etc/docker/daemon.json
{
  "insecure-registries" : ["registry.mycompany.com:5000"]
}

Then restart Docker:

systemctl restart docker

๐Ÿ”‘ Managing Credentials Securely

Docker stores auth credentials in ~/.docker/config.json. To prevent leakage:

๐Ÿš€ Recap: Image Lifecycle

  1. ๐Ÿ›  Build your image locally.
  2. ๐Ÿท Tag the image with registry address.
  3. ๐Ÿ” Login to the registry.
  4. โฌ†๏ธ Push to registry.
  5. โฌ‡๏ธ Pull on another host.

๐Ÿ“Œ Summary

Next time someone says "where's your image?", you'll know exactly how to store, tag, push, and secure your Docker builds like a pro ๐Ÿ’ช.

In our next post, we'll dive into ๐Ÿ•ธ (Post 5): Orchestrating Containers with Docker Swarm & Kubernetes Basics!

โ€” Blog by Aelify (ML2AI.com)

๐Ÿ“š Documentation Index