GitHub Professional Certificate GitHub Packages and Container Registry 1 — Questions and Answers
Question 1: What is the base URL for authenticating with the GitHub Container Registry (GHCR)?
- docker.pkg.github.com
- ghcr.io (Correct answer)
- registry.github.com
- packages.github.com
Correct answer: ghcr.io
GitHub Container Registry uses ghcr.io as its base URL for authentication and image pulls/pushes.
Question 2: Which command correctly logs Docker into the GitHub Container Registry using a Personal Access Token stored in an environment variable TOKEN?
- docker auth login ghcr.io -u USERNAME -p $TOKEN
- echo $TOKEN | docker login ghcr.io -u USERNAME --password-stdin (Correct answer)
- docker login --token $TOKEN ghcr.io
- gh auth login --docker ghcr.io --token $TOKEN
Correct answer: echo $TOKEN | docker login ghcr.io -u USERNAME --password-stdin
Piping the token via --password-stdin is the recommended secure approach to avoid exposing the token in shell history.
Question 3: What minimum permission scope is required on a Personal Access Token (classic) to publish packages to GitHub Packages?
- read:packages
- write:packages (Correct answer)
- repo
- admin:org
Correct answer: write:packages
The write:packages scope is required to upload and publish package versions to GitHub Packages.
Question 4: Which package ecosystems does GitHub Packages natively support? (Select the most complete answer)
- npm, Maven, and Docker only
- npm, RubyGems, Maven, Gradle, Docker, NuGet, and Swift (Correct answer)
- pip, npm, and Cargo only
- npm, Docker, NuGet, and Helm only
Correct answer: npm, RubyGems, Maven, Gradle, Docker, NuGet, and Swift
GitHub Packages supports npm, RubyGems, Maven, Gradle, Docker/OCI containers, NuGet, and Swift package registries.
Question 5: How do you tag and push a Docker image to GitHub Container Registry for the user 'octocat' and image 'myapp'?
- docker push octocat/myapp:latest to ghcr.io
- docker tag myapp ghcr.io/octocat/myapp:latest && docker push ghcr.io/octocat/myapp:latest (Correct answer)
- gh package push --image myapp --registry ghcr.io
- docker upload ghcr.io/octocat/myapp:latest
Correct answer: docker tag myapp ghcr.io/octocat/myapp:latest && docker push ghcr.io/octocat/myapp:latest
You must tag the image with the full ghcr.io path including namespace before pushing with docker push.
Question 6: Where should the .npmrc file be configured to redirect npm installs to GitHub Packages for a scoped package @myorg?
- In the global npm config only
- In the project root with @myorg:registry=https://npm.pkg.github.com (Correct answer)
- In the GitHub Actions runner environment
- In the repository's package.json under 'registries'
Correct answer: In the project root with @myorg:registry=https://npm.pkg.github.com
A .npmrc file in the project root with the scoped registry entry directs npm to use GitHub Packages for that organization's packages.
Question 7: By default, what visibility does a package published from a private repository inherit on GitHub Packages?
- Public, regardless of repository visibility
- Private, matching the repository visibility (Correct answer)
- Internal, accessible only to organization members
- It depends on the package ecosystem
Correct answer: Private, matching the repository visibility
Packages published from private repositories are private by default, inheriting the repository's visibility setting.
What is the base URL for authenticating with the GitHub Container Registry (GHCR)?