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)