Skip to content
Ameen Abozaid
JNR-049

Docker fundamentals

  • 8 Lessons
  • 3 h practice (estimate)
On this page 8 topics

Overview

Topics

  • Images
  • containers
  • Dockerfiles
  • volumes
  • networking

Learn first

3 h of practice (estimate)

Learning outcomes

  1. Explain images, containers, layers, and registries, and how containers differ from VMs.
  2. Write a multi-stage Dockerfile for a Spring Boot app that runs as a non-root user.
  3. Use volumes for persistent data and port mapping for access.
  4. Connect containers on a user-defined network.
  5. Inspect running containers (logs, exec, inspect).

Lessons

  1. 01Why containers
  2. 02Images, layers, registries
  3. 03Running containers
  4. 04Writing a Dockerfile for Spring Boot
  5. 05Volumes and networks
  6. 06Debugging containers
  7. 07Demo: writing a multi-stage Dockerfile for Shop
  8. 08Demo: debugging a crashing container

Lab and exercises

Lab

JNR-049-LAB1 · Containerize Shop

Outcomes: 1–5 · Time: ~3 h Build a multi-stage, non-root Shop image under 300 MB. Run PostgreSQL in a container with a volume and connect Shop through a user-defined network. Acceptance: data survives container removal.

Exercises (assessment: review and improve a poor Dockerfile)

IDOutcomeTask
JNR-049-EX011Explain in four sentences the difference between an image and a container, and between a container and a VM.
JNR-049-EX022Convert a single-stage Dockerfile (JDK, Maven, source, JAR in one image) into a multi-stage build.
JNR-049-EX032Add a non-root user and a .dockerignore; prove with docker exec that the app is not root.
JNR-049-EX043Run PostgreSQL with a named volume, insert a row, remove the container, start a new one, and show the row.
JNR-049-EX053Map the app to host port 9090 while it listens on 8080 inside.
JNR-049-EX064Create a network and make the app reach the database by name.
JNR-049-EX075A container exits immediately. List the three commands you use first and what each shows.
Show solutions
  • EX01 An image is a read-only template of layers; a container is a running instance. A VM has its own OS kernel; a container shares the host kernel and is lighter.
  • EX02 Stage one FROM eclipse-temurin:<jdk> AS build runs Maven; stage two FROM eclipse-temurin:<jre> does COPY --from=build for the JAR only.
  • EX03 RUN useradd -r shop and USER shop; docker exec shop whoami prints shop. .dockerignore lists target/, .git, .env.
  • EX04 -v pgdata:/var/lib/postgresql/data; after docker rm -f and a new docker run with the same volume, select returns the row.
  • EX05 docker run -p 9090:8080 shop:1.0.
  • EX06 docker network create shop-net; start both with --network shop-net; set SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/shop.
  • EX07 docker ps -a (exit code), docker logs NAME (error message), docker inspect NAME (env, mounts, ports).
  • Common mistakes (latest, secrets baked into images, building inside the final image) are checked in the assessment review.

Quiz

Outcomes: O1 concepts · O2 Dockerfile · O3 volumes and ports · O4 networks · O5 inspecting.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1A running instance of an image is a:O1
  2. 2Compared with a VM, a container:O1
  3. 3The main benefit of a multi-stage build:O2
  4. 4To run as non-root in a Dockerfile:O2
  5. 5Which tag practice is best?O2
  6. 6Data that must survive container removal belongs in a:O3
  7. 7-p 9090:8080 means:O3
  8. 8On a user-defined network, the app reaches the database container db using:O4
  9. 9Which shows a container's app output?O5
  10. 10Which opens a shell inside a running container?O5

Practical part

Seven exercises JNR-049-EX01 to EX07 plus the lab; for the assessment, review a poor Dockerfile and submit an improved version. Pass: quiz 8/10, at least five exercises correct, image under 300 MB, and data surviving container removal.

Common mistakes

Building inside the final image; latest tags; secrets baked into images.

Assessment

Review and improve a poor Dockerfile.

Career relevance

Kubernetes (MID-057).

Type to search levels, phases, modules and lessons.