DEV Community

Darshan Vasani
Darshan Vasani Subscriber

Posted on • Edited on

πŸ“˜ Complete Docker Image Publishing CheatSheet πŸ³πŸš€

πŸ“˜ Complete Docker Image Publishing CheatSheet πŸ³πŸš€


🌐 What is a Docker Registry?

A Docker registry is a storage for Docker images πŸ—ƒοΈ. You can:

  • βœ… Push your custom images to it
  • πŸ“₯ Pull images when needed
  • πŸ” Optionally set them private/public

🏠 Popular Registries:

  • 🐳 Docker Hub (hub.docker.com)
  • πŸ” GitHub Container Registry (ghcr.io)
  • ☁️ Google Artifact Registry / Amazon ECR / GitLab / Azure ACR

✨ Structure of Docker Image Name

<registry>/<username>/<repo>:<tag>
Enter fullscreen mode Exit fullscreen mode
Part Example Meaning
Registry docker.io (default) Where image is stored 🌍
Username dpvasani56 Your DockerHub or GitHub ID πŸ‘€
Repo node-application Your app/project name πŸ“¦
Tag v1, latest Version tag 🏷️

πŸš€ Two Ways to Publish Docker Image to Docker Hub

πŸ“¦ Step 0: Build the image

docker build -t dpvasani56/node-application:v1 .
Enter fullscreen mode Exit fullscreen mode

🧭 Method 1: Manual Push to Docker Hub

βœ… Step-by-step:

1️⃣ Login to Docker Hub

docker login
Enter fullscreen mode Exit fullscreen mode

🧠 Enter your Docker Hub username and password.


2️⃣ Push your image

docker push dpvasani56/node-application:v1
Enter fullscreen mode Exit fullscreen mode

βœ… Image will now appear on your Docker Hub at:
πŸ“ https://hub.docker.com/r/dpvasani56/node-application


3️⃣ Pull from any system

docker pull dpvasani56/node-application:v1
Enter fullscreen mode Exit fullscreen mode

🎯 Then run:

docker run -p 3000:3000 dpvasani56/node-application:v1
Enter fullscreen mode Exit fullscreen mode

🧠 Method 2: Push from GitHub via GitHub Container Registry (ghcr.io)


πŸ”§ Step-by-step:

1️⃣ Create a GitHub repo

Name it like: node-application


2️⃣ Login to GitHub Container Registry

echo <GH_TOKEN> | docker login ghcr.io -u USERNAME --password-stdin
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Use a Personal Access Token (PAT) from GitHub with write:packages permission.


3️⃣ Tag your image

docker tag node-application ghcr.io/dpvasani56/node-application:v1
Enter fullscreen mode Exit fullscreen mode

4️⃣ Push to GitHub Container Registry

docker push ghcr.io/dpvasani56/node-application:v1
Enter fullscreen mode Exit fullscreen mode

βœ… Image is now available at:
πŸ”— https://github.com/dpvasani56/packages


πŸ“Œ Tagging Summary

# Tag for DockerHub
docker tag node-application dpvasani56/node-application:v1

# Tag for GitHub Registry
docker tag node-application ghcr.io/dpvasani56/node-application:v1
Enter fullscreen mode Exit fullscreen mode

🧼 Optional Cleanup

docker image rm <image-name>
Enter fullscreen mode Exit fullscreen mode

Use this to save space once pushed.


🧠 Bonus: Automate with GitHub Actions

Use this snippet in .github/workflows/docker.yml:

jobs:
  push_to_registry:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Log in to GitHub Container Registry
        run: echo "${{ secrets.GH_PAT }}" | docker login ghcr.io -u dpvasani56 --password-stdin

      - name: Build and Push
        run: |
          docker build -t ghcr.io/dpvasani56/node-application:v1 .
          docker push ghcr.io/dpvasani56/node-application:v1
Enter fullscreen mode Exit fullscreen mode

βœ… Set GH_PAT as a GitHub secret with correct permissions.


πŸ”₯ Quick Recap Table

Action Docker Hub GitHub Container Registry
Login docker login docker login ghcr.io
Tag dpvasani56/app:v1 ghcr.io/dpvasani56/app:v1
Push docker push dpvasani56/app:v1 docker push ghcr.io/dpvasani56/app:v1
Pull docker pull dpvasani56/app:v1 docker pull ghcr.io/dpvasani56/app:v1

🧾 Sample Push Command (Your Request)

docker push dpvasani56/node-application:v1
Enter fullscreen mode Exit fullscreen mode

βœ… This pushes your image to Docker Hub under your account.


🏷️ Step-by-Step: Tag & Push Docker Image to Docker Hub (dpvasani56/node-application)

Assume your image is locally named:

my-app
Enter fullscreen mode Exit fullscreen mode

And you want to push it as:
πŸ“¦ dpvasani56/node-application


πŸ”§ Step 1: Tag the Image

🏷️ Think of this as giving your image a Docker Hub label 🎫

docker tag my-app dpvasani56/node-application
Enter fullscreen mode Exit fullscreen mode

βœ… This tags your image for Docker Hub upload.


βœ… Optional: Add a Version Tag

docker tag my-app dpvasani56/node-application:v1
Enter fullscreen mode Exit fullscreen mode

🎯 This is better for version control in CI/CD and releases.


πŸ” Step 2: Login to Docker Hub

docker login
Enter fullscreen mode Exit fullscreen mode

➑️ Enter Docker Hub credentials for dpvasani56.


πŸ“€ Step 3: Push the Image

πŸ‘‰ With version tag:

docker push dpvasani56/node-application:v1
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ Or default (latest tag):

docker push dpvasani56/node-application
Enter fullscreen mode Exit fullscreen mode

βœ… Image now available at:
πŸ”— https://hub.docker.com/r/dpvasani56/node-application


πŸ“₯ Step 4: Pull & Use It Anywhere

docker pull dpvasani56/node-application:v1
Enter fullscreen mode Exit fullscreen mode

Run the app:

docker run -p 3000:3000 dpvasani56/node-application:v1
Enter fullscreen mode Exit fullscreen mode

πŸ“¦ All Commands Recap

# πŸ”¨ Build your image
docker build -t my-app .

# 🏷️ Tag for Docker Hub
docker tag my-app dpvasani56/node-application:v1

# πŸ” Login to Docker Hub
docker login

# πŸ“€ Push to Docker Hub
docker push dpvasani56/node-application:v1

# πŸ“₯ Pull from Docker Hub (anywhere)
docker pull dpvasani56/node-application:v1

# ▢️ Run it
docker run -p 3000:3000 dpvasani56/node-application:v1
Enter fullscreen mode Exit fullscreen mode

🧠 Helpful Tips

Command Use
docker images View tagged images locally πŸ—‚οΈ
docker rmi <image> Remove an image locally 🧹
docker ps View running containers πŸš€
docker stop <id> Stop a container manually πŸ›‘

Top comments (0)