Script Valley
Docker: Complete Course
Building Docker Images with Dockerfile/Assessment

Practice & Assessment

Test your understanding of Building Docker Images with Dockerfile

Multiple Choice Questions

6
1

Which Dockerfile instruction order maximizes layer cache reuse for a Node.js app?

2

In a multi-stage build, what does `COPY --from=builder /app/dist ./dist` do?

3

What is the primary purpose of .dockerignore?

4

What is the difference between CMD and ENTRYPOINT in a Dockerfile?

5

You run `docker build --no-cache -t app .` — what does --no-cache do?

6

Which image tag strategy is safest for production deployments?

Coding Challenges

1
1

Build a minimal Node.js API image using multi-stage build

Given a Node.js Express app with TypeScript source in ./src and a build script that outputs to ./dist, write a two-stage Dockerfile. Stage 1 (named 'builder'): use node:20-alpine, copy package files, run npm ci, copy source, run npm run build. Stage 2 (production): use node:20-alpine, copy package files, run npm ci --omit=dev, copy only /app/dist from builder stage, set NODE_ENV=production, expose port 3000, start with CMD ["node", "dist/index.js"]. Also write a .dockerignore excluding node_modules, .git, dist, and .env files. Build the image tagged as 'my-api:1.0.0' and verify with docker images that it is under 200MB. Estimated time: 25 minutes.

Medium

Mini Project

1

Optimized Python Flask Image

Build a production-ready Docker image for a Python Flask app from scratch. Requirements: (1) Start from python:3.12-slim as base image, (2) Set WORKDIR to /app, (3) Copy requirements.txt first and run pip install --no-cache-dir before copying source to maximize cache efficiency, (4) Copy the rest of the source, (5) Set ENV FLASK_ENV=production and ENV PORT=5000, (6) Expose port 5000, (7) Use ENTRYPOINT ["python"] and CMD ["app.py"]. Write a .dockerignore that excludes __pycache__, .git, .env, venv, and *.pyc files. Build the image and record its size. Then add a multi-stage step: use a build stage to install dependencies into a virtual environment, then copy only the venv and source into a python:3.12-slim final stage, removing pip from the final image. Compare both image sizes and document the reduction in a README.

Medium