Practice & Assessment
Test your understanding of Docker and Container Workflows
Multiple Choice Questions
5What permission must be granted for GITHUB_TOKEN to push images to GitHub Container Registry?
What does fail-fast: false do in a matrix strategy?
How does GitHub ensure a service container is ready before workflow steps start?
What does tagging a Docker image with github.sha achieve?
What is the cache-to: type=gha,mode=max option in docker/build-push-action?
Coding Challenges
1Build and Push a Docker Image to ghcr.io
Create a Node.js application with a valid Dockerfile. Write a GitHub Actions workflow that triggers on push to main. The workflow must: log in to ghcr.io using docker/login-action with GITHUB_TOKEN, build and push the image to ghcr.io using docker/build-push-action with gha layer caching enabled, and tag the image with both github.sha and latest. Set the packages: write permission. Expected output: the image visible in the repository's Packages tab on GitHub. Verify by navigating to github.com/[owner]/[repo]/pkgs/container/[image]. Estimated time: 25 minutes.
Mini Project
Containerized Integration Test Pipeline
Build a CI workflow for a Node.js REST API that uses PostgreSQL. The workflow triggers on pull_request to main and has two jobs. Job 1 (unit-tests): runs on ubuntu-latest, uses Node 20 with npm caching, runs npm ci and npm test. Job 2 (integration-tests): runs on ubuntu-latest with a postgres:16 service container (password testpassword, database testdb, with pg_isready health check on port 5432), runs npm ci and npm run test:integration with DATABASE_URL pointing to the service. Add a matrix strategy to the unit-tests job to run against Node 18 and Node 20 with fail-fast: false. Job 2 needs job 1. Verify all matrix combinations and the integration test job pass.
