โShow me how to authenticate to ghcr.io with a GitHub token via --password-stdin and push my image as ghcr.io/username/myapp:latest.โ
11 โ [Optional] Push to GitHub Container Registry (GHCR)
Category: Registry ยท Priority: Low ยท Optional
Use
ghcr.io/username/myapp:latest. Authenticate withecho $GITHUB_TOKEN | docker login ghcr.io -u USERNAME --password-stdin.
๐ฏ What is this task?
GitHub Container Registry (GHCR) is an alternative to Docker Hub โ it stores your Docker images directly inside your GitHub account. It's useful because your image and your code live in the same place. This task is optional but good to know.
๐ค AI Prompt
"Show me step by step how to create a GitHub Personal Access Token with the right permissions for GHCR, authenticate Docker with GHCR, tag my local Docker image for GHCR, and push it. My GitHub username is
yourusernameand image name ismy-docker-app."
๐ Step-by-step
Step 1 โ Create a GitHub Personal Access Token (PAT)
- Go to GitHub โ Settings โ Developer Settings โ Personal Access Tokens โ Tokens (classic)
- Click "Generate new token (classic)"
- Give it a name like
docker-ghcr - Select these scopes:
write:packages,read:packages,delete:packages - Click "Generate token" and copy it immediately (you can't see it again)
Step 2 โ Log in to GHCR
In your terminal (replace yourusername and paste your token):
echo "YOUR_TOKEN_HERE" | docker login ghcr.io -u yourusername --password-stdin
You should see Login Succeeded.
Step 3 โ Tag your image for GHCR
docker tag my-docker-app:v5 ghcr.io/yourusername/my-docker-app:v1.0.0
docker tag my-docker-app:v5 ghcr.io/yourusername/my-docker-app:latest
Step 4 โ Push to GHCR
docker push ghcr.io/yourusername/my-docker-app:v1.0.0
docker push ghcr.io/yourusername/my-docker-app:latest
Step 5 โ Verify
Go to https://github.com/yourusername?tab=packages โ your image should appear under "Packages".
โ Done when
- GitHub PAT created with package permissions
-
docker login ghcr.iosucceeds - Image pushed and visible at
github.com/yourusername?tab=packages
๐ Quiz
Answer all 2 questions correctly to complete this lesson.