nerdexam
Microsoft

AZ-400 · Question #506

Hotspot Question You have a GitHub repository. You plan to use the repository to create a container. You need to configure GitHub Actions to deploy the container to GitHub Container Registry. How shou

The correct answer is name: Step 1: docker build --file Dockerfile --tag ${ { github.repository } }:latest --label "runnumber=${ { github.run_number } }"; name: Step 2: echo $GITHUB_TOKEN | docker login ghr.io -u USERNAME --password-stdin; name: Step 3: docker push ghr.io/${ { github.repository_owner } }/${ { github.repository } }:latest. This question requires configuring a GitHub Actions workflow to build a container image and deploy it to GitHub Container Registry. The process involves three main steps: Step 1: Build the Docker Image The correct command is docker build --file Dockerfile --tag ${ { github.reposi

Submitted by parkjh· Mar 6, 2026Design and implement build and release pipelines

Question

Hotspot Question You have a GitHub repository. You plan to use the repository to create a container. You need to configure GitHub Actions to deploy the container to GitHub Container Registry. How should you complete the script? To answer, select the appropriate options in the answer area. NOTE: Each correct selection is worth one point. Answer:

Exhibit

AZ-400 question #506 exhibit

Answer Area

  • name: Step 1docker build --file Dockerfile --tag ${ { github.repository } }:latest --label "runnumber=${ { github.run_number } }"
    docker build --file Dockerfile --tag ${ { github.repository } }:latest --label "runnumber=${ { github.run_number } }"docker login ghr.io -u USERNAME --password-stdindocker pull ghr.io/${ { github.repository_owner } }/${ { github.repository } }:latestdocker push ghr.io/${ { github.repository_owner } }/${ { github.repository } }:latestecho $GITHUB_TOKEN | docker login ghr.io -u USERNAME --password-stdinuses: azure/docker-login@v1
  • name: Step 2echo $GITHUB_TOKEN | docker login ghr.io -u USERNAME --password-stdin
    docker build --file Dockerfile --tag ${ { github.repository } }:latest --label "runnumber=${ { github.run_number } }"docker login ghr.io -u USERNAME --password-stdindocker pull ghr.io/${ { github.repository_owner } }/${ { github.repository } }:latestdocker push ghr.io/${ { github.repository_owner } }/${ { github.repository } }:latestecho $GITHUB_TOKEN | docker login ghr.io -u USERNAME --password-stdinuses: azure/docker-login@v1
  • name: Step 3docker push ghr.io/${ { github.repository_owner } }/${ { github.repository } }:latest
    docker build --file Dockerfile --tag ${ { github.repository } }:latest --label "runnumber=${ { github.run_number } }"docker login ghr.io -u USERNAME --password-stdindocker pull ghr.io/${ { github.repository_owner } }/${ { github.repository } }:latestdocker push ghr.io/${ { github.repository_owner } }/${ { github.repository } }:latestecho $GITHUB_TOKEN | docker login ghr.io -u USERNAME --password-stdinuses: azure/docker-login@v1

Explanation

This question requires configuring a GitHub Actions workflow to build a container image and deploy it to GitHub Container Registry. The process involves three main steps:

  • Step 1: Build the Docker Image The correct command is docker build --file Dockerfile --tag ${ { github.repository } }:latest --label "runnumber=${ { github.run_number } }". This command builds the Docker image from the Dockerfile in the repository. It tags the image with the repository name and latest tag, using the github.repository context variable. Additionally, it adds a label to the image containing the GitHub Actions run number, provided by github.run_number.

  • Step 2: Log in to GitHub Container Registry The correct command is echo $GITHUB_TOKEN | docker login ghr.io -u USERNAME --password-stdin. Before pushing an image, authentication to the container registry is necessary. This command uses the GITHUB_TOKEN (a temporary token automatically generated by GitHub Actions) to log into ghr.io (the domain for GitHub Container Registry). The token is piped to docker login via standard input (--password-stdin). While USERNAME is provided in the option, with GITHUB_TOKEN and --password-stdin, the actual username usually isn't critical or can be GITHUB_ACTOR.

  • Step 3: Push the Docker Image to GitHub Container Registry The correct command is docker push ghr.io/${ { github.repository_owner } }/${ { github.repository } }:latest. After building the image and authenticating, this command pushes the locally built and tagged image to the GitHub Container Registry. The image name follows the pattern ghr.io/<owner>/<repository-name>:<tag>, constructed using the github.repository_owner and github.repository context variables along with the latest tag.

Topics

#GitHub Actions#Docker/Containers#CI/CD Pipeline#Container Registry Authentication

Community Discussion

No community discussion yet for this question.

Full AZ-400 Practice