Project 1 โ€บ 11 Push to GHCRGitHub โ†—
๐Ÿค– AI Prompt โ€” stuck? paste this

โ€œ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 with echo $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 yourusername and image name is my-docker-app."

๐Ÿ“‹ Step-by-step

Step 1 โ€” Create a GitHub Personal Access Token (PAT)

  1. Go to GitHub โ†’ Settings โ†’ Developer Settings โ†’ Personal Access Tokens โ†’ Tokens (classic)
  2. Click "Generate new token (classic)"
  3. Give it a name like docker-ghcr
  4. Select these scopes: write:packages, read:packages, delete:packages
  5. 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.io succeeds
  • Image pushed and visible at github.com/yourusername?tab=packages

๐Ÿ“ Quiz

Answer all 2 questions correctly to complete this lesson.

1. What is GHCR?
2. What's the safest way to pass a token to `docker login`?
โ† PreviousPass the quiz to completeNext โ†’