0
0
Dockerdevops~20 mins

GitHub Actions with Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker GitHub Actions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of Docker build in GitHub Actions
You have this GitHub Actions step to build a Docker image:
      - name: Build Docker Image
        run: docker build -t myapp:latest .

What will be the output if the Dockerfile is missing in the repository root?
AError: Cannot locate Dockerfile: No such file or directory
BSuccessfully builds the image with default settings
CBuild completes but image is empty
DWarning: Dockerfile not found, using default base image
Attempts:
2 left
💡 Hint
Docker build requires a Dockerfile in the specified context directory.
🔀 Workflow
intermediate
2:00remaining
Correct GitHub Actions step to push Docker image
Which GitHub Actions step correctly logs in to Docker Hub and pushes an image named 'myapp:latest'?
A
- name: Push Docker Image
  run: |
    docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASS }}
    docker push myapp:latest
B
- name: Push Docker Image
  run: |
    docker push myapp:latest
    docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASS }}
C
- name: Push Docker Image
  run: |
    docker login ${{ secrets.DOCKER_USER }} ${{ secrets.DOCKER_PASS }}
    docker push myapp:latest
D
- name: Push Docker Image
  run: |
    docker push myapp:latest
Attempts:
2 left
💡 Hint
Docker login must happen before pushing the image.
Configuration
advanced
2:00remaining
GitHub Actions Docker cache usage
You want to speed up Docker builds in GitHub Actions by caching layers. Which configuration snippet correctly uses the official Docker cache action?
A
- name: Cache Docker layers
  uses: docker/build-push-action@v4
  with:
    cache-from: type=local,src=/tmp/.buildx-cache
    cache-to: type=local,dest=/tmp/.buildx-cache
B
- name: Cache Docker layers
  uses: actions/cache@v3
  with:
    path: /tmp/.buildx-cache
    key: ${{ runner.os }}-buildx-${{ hashFiles('**/Dockerfile') }}
C
- name: Cache Docker layers
  uses: actions/cache@v3
  with:
    path: /var/lib/docker
    key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}
D
- name: Cache Docker layers
  uses: actions/cache@v3
  with:
    path: /tmp/.buildx-cache
    key: ${{ runner.os }}-buildx-${{ github.sha }}
Attempts:
2 left
💡 Hint
Cache key should depend on Dockerfile content hash for cache invalidation.
Troubleshoot
advanced
2:00remaining
Diagnosing Docker build failure in GitHub Actions
A GitHub Actions workflow fails with this error during docker build:
failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /github/workspace/Dockerfile: no such file or directory

What is the most likely cause?
AThe docker build command is missing the -t tag option
BDocker daemon is not running on the GitHub runner
CThe Dockerfile is named incorrectly or missing in the repository root
DThe GitHub Actions runner lacks permissions to run docker commands
Attempts:
2 left
💡 Hint
The error says it cannot open the Dockerfile file.
Best Practice
expert
3:00remaining
Optimal multi-stage Docker build in GitHub Actions
You want to build a multi-stage Docker image in GitHub Actions to reduce final image size. Which Dockerfile snippet correctly implements a two-stage build for a Go application?
A
FROM golang:1.20 AS builder
WORKDIR /app
COPY . .
RUN go build -o myapp
FROM alpine:latest
COPY myapp /usr/local/bin/myapp
CMD ["myapp"]
B
FROM alpine:latest AS builder
WORKDIR /app
COPY . .
RUN go build -o myapp
FROM golang:1.20
COPY --from=builder /app/myapp /usr/local/bin/myapp
CMD ["myapp"]
C
FROM golang:1.20
WORKDIR /app
COPY . .
RUN go build -o myapp
FROM alpine:latest
COPY /app/myapp /usr/local/bin/myapp
CMD ["myapp"]
D
FROM golang:1.20 AS builder
WORKDIR /app
COPY . .
RUN go build -o myapp
FROM alpine:latest
COPY --from=builder /app/myapp /usr/local/bin/myapp
CMD ["myapp"]
Attempts:
2 left
💡 Hint
The final stage should copy the binary from the builder stage using --from.