GitHub Actions is a tool that helps automate tasks like testing and deploying code when you push changes to your GitHub repository.
Click to reveal answer
beginner
How does Docker fit into GitHub Actions?
Docker lets you package your app and its environment into a container. GitHub Actions can build and run these Docker containers automatically during workflows.
Click to reveal answer
beginner
What is a workflow file in GitHub Actions?
A workflow file is a YAML file in your repo that tells GitHub Actions what steps to run and when, like building a Docker image after code changes.
Click to reveal answer
intermediate
What does the 'docker/build-push-action' do in a GitHub Actions workflow?
It builds a Docker image from your code and can push it to a container registry like Docker Hub automatically.
Click to reveal answer
beginner
Why use GitHub Actions with Docker instead of manual builds?
It saves time by automating builds and tests, ensures consistency, and helps catch errors early before deploying your app.
Click to reveal answer
What file format is used to define GitHub Actions workflows?
AXML
BJSON
CTXT
DYAML
✗ Incorrect
GitHub Actions workflows are defined using YAML files, which are easy to read and write.
Which GitHub Actions step is commonly used to build and push Docker images?
Aactions/checkout
Bactions/setup-node
Cdocker/build-push-action
Dactions/upload-artifact
✗ Incorrect
The 'docker/build-push-action' is designed to build Docker images and push them to registries.
What triggers a GitHub Actions workflow by default?
AA push to the repository
BOpening a new issue
CDeleting a branch
DViewing the repository
✗ Incorrect
Workflows often trigger automatically when you push code changes to the repository.
Why use Docker containers in CI/CD pipelines?
ATo slow down the build process
BTo run code in a consistent environment
CTo avoid using version control
DTo delete code automatically
✗ Incorrect
Docker containers ensure your app runs the same way everywhere by packaging all dependencies.
Where can Docker images be pushed from GitHub Actions?
ADocker Hub or other container registries
BGitHub Issues
CGitHub Wiki
DLocal text files
✗ Incorrect
Docker images are pushed to container registries like Docker Hub for storage and sharing.
Explain how you would set up a GitHub Actions workflow to build and push a Docker image when code is pushed.
Think about the steps from code push to Docker image upload.
You got /5 concepts.
Describe the benefits of using GitHub Actions with Docker in a software project.
Consider how automation and containers improve development.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of using GitHub Actions with Docker in a project?
easy
A. To automate building and testing Docker images on code changes
B. To manually run Docker commands on your local machine
C. To replace Docker with a different container tool
D. To write Dockerfiles without using any commands
Solution
Step 1: Understand GitHub Actions role
GitHub Actions automates tasks like building and testing when code changes happen.
Step 2: Connect automation with Docker
Using GitHub Actions with Docker means automating Docker image builds and tests on events like pushes.
Final Answer:
To automate building and testing Docker images on code changes -> Option A
Quick Check:
Automation with Docker = D [OK]
Hint: GitHub Actions automate tasks triggered by code events [OK]
Common Mistakes:
Thinking GitHub Actions replace Docker itself
Confusing manual commands with automation
Assuming Dockerfiles are written by GitHub Actions
2. Which of the following is the correct syntax to build a Docker image inside a GitHub Actions workflow step?
easy
A. run: docker start -t myimage .
B. run: docker create myimage .
C. run: docker push -t myimage .
D. run: docker build -t myimage .
Solution
Step 1: Recall Docker build command
The command to build an image is 'docker build' with '-t' to tag the image.
Step 2: Match with GitHub Actions step syntax
In GitHub Actions, 'run:' is used to run shell commands, so 'run: docker build -t myimage .' is correct.
Final Answer:
run: docker build -t myimage . -> Option D
Quick Check:
Build image command = C [OK]
Hint: Use 'docker build -t name .' to build images [OK]
What will be the output when this step runs successfully?
medium
A. test-image
B. Hello
C. docker build completed
D. Error: image not found
Solution
Step 1: Understand the commands run
The first command builds an image tagged 'test-image'. The second runs a container from it that prints 'Hello'.
Step 2: Identify the output of the run command
The 'docker run' command runs 'echo Hello' inside the container, so the output is 'Hello'.
Final Answer:
Hello -> Option B
Quick Check:
docker run echo output = Hello [OK]
Hint: Run command output is what container prints [OK]
Common Mistakes:
Thinking build command outputs 'test-image'
Expecting build success message as output
Assuming image not found error without build
4. You have this GitHub Actions step:
run: docker build -t myapp .
run: docker run myapp
The workflow fails with 'Error: Dockerfile not found'. What is the likely cause?
medium
A. The Dockerfile is missing in the repository
B. The two 'run' commands are separate steps and do not share state
C. The image name 'myapp' is invalid
D. The 'docker run' command syntax is incorrect
Solution
Step 1: Understand docker build requirement
The 'docker build .' command requires a Dockerfile in the current directory (repo root after checkout).
Step 2: Identify the error cause
If the Dockerfile is missing from the repository, the build step fails with 'Dockerfile not found' error.
Final Answer:
The Dockerfile is missing in the repository -> Option A
Quick Check:
docker build fails = no Dockerfile [OK]
Hint: Ensure Dockerfile exists in repository root [OK]
Common Mistakes:
Thinking separate steps prevent image sharing
Assuming image name 'myapp' is invalid
Believing 'docker run' syntax causes the error
5. You want to create a GitHub Actions workflow that builds a Docker image only when a push happens to the 'main' branch and then pushes the image to Docker Hub. Which of these YAML snippets correctly sets the trigger and steps?
hard
A. on:
push:
tags:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: docker build -t myuser/myapp .
- run: docker push myuser/myapp
B. on:
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: docker build -t myapp .
- run: docker push myapp