π 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>
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 .
π§ Method 1: Manual Push to Docker Hub
β Step-by-step:
1οΈβ£ Login to Docker Hub
docker login
π§ Enter your Docker Hub username and password.
2οΈβ£ Push your image
docker push dpvasani56/node-application:v1
β
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
π― Then run:
docker run -p 3000:3000 dpvasani56/node-application:v1
π§ 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
π‘ 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
4οΈβ£ Push to GitHub Container Registry
docker push ghcr.io/dpvasani56/node-application:v1
β
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
π§Ό Optional Cleanup
docker image rm <image-name>
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
β
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
β 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
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
β This tags your image for Docker Hub upload.
β Optional: Add a Version Tag
docker tag my-app dpvasani56/node-application:v1
π― This is better for version control in CI/CD and releases.
π Step 2: Login to Docker Hub
docker login
β‘οΈ Enter Docker Hub credentials for dpvasani56
.
π€ Step 3: Push the Image
π With version tag:
docker push dpvasani56/node-application:v1
π Or default (latest
tag):
docker push dpvasani56/node-application
β
Image now available at:
π https://hub.docker.com/r/dpvasani56/node-application
π₯ Step 4: Pull & Use It Anywhere
docker pull dpvasani56/node-application:v1
Run the app:
docker run -p 3000:3000 dpvasani56/node-application:v1
π¦ 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
π§ 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)