Docker flashcards: 50 essentials for developers
Learn Docker from images and layers to multi-stage builds, volumes, networks and Compose, with the commands and best practices you use daily.
Practice now
Study without an account
Scheduled with the default Askesis timings. Progress is saved in this browser.
All 50 cards
- 1Image vs containerAn image is a read-only template made of layers; a container is a running (or stopped) instance of an image with its own writable layer
- 2What creates a new image layer?Instructions that change the filesystem, mainly
RUN,COPYandADD - 3When does Docker’s build cache stop being reused?At the first instruction whose inputs changed; every instruction after it is rebuilt
- 4Order a Node.js Dockerfile so dependency installs stay cacheddockerfile
COPY package.json package-lock.json ./ RUN npm ci COPY . .Copying the lockfile first means code changes don’t invalidate thenpm cilayer. - 5What does
FROMdo?Sets the base image for the build stage; every Dockerfile starts with it (after optionalARGs) - 6
COPYvsADDCOPYcopies files from the build context;ADDcan also fetch URLs and auto-extract local tar archivesPreferCOPYunless you need those extras. - 7
CMDvsENTRYPOINTENTRYPOINTsets the executable;CMDsets default arguments (or the default command) thatdocker runarguments replace - 8Exec form vs shell formExec form (JSON array) runs the program directly as PID 1 so it receives signals; shell form wraps it in
/bin/sh -cdockerfileCMD ["node", "server.js"] # exec form CMD node server.js # shell form - 9
ARGvsENVARGexists only at build time;ENVis set at build time and persists into running containers - 10What does
WORKDIRdo?Sets (and creates if needed) the working directory for later instructions and for the container - 11Run the container as a non-root userdockerfile
RUN useradd --create-home app USER appOfficial Node images already include anodeuser:USER node. - 12What does
EXPOSE 3000do?Documents the port the app listens on; it doesn’t publish it. Use-pat run time - 13Add a health check to an imagedockerfile
HEALTHCHECK --interval=30s --timeout=3s \ CMD curl -fsS http://localhost:3000/health || exit 1 - 14Multi-stage buildBuild in one stage and copy only the artifacts into a small final imagedockerfile
FROM node:22 AS build WORKDIR /app COPY . . RUN npm ci && npm run build FROM node:22-slim WORKDIR /app COPY --from=build /app/dist ./dist CMD ["node", "dist/server.js"] - 15What is
.dockerignorefor?Excludes files from the build context (likenode_modules,.git,.env), making builds faster and images safer - 16What is the build context?The set of files sent to the builder, usually the directory passed to
docker build(often.) - 17Build and tag an imagebash
docker build -t myapp:1.0 . - 18Run a container detached, named, with a published portbash
docker run -d --name web -p 8080:80 nginx - 19In
-p 8080:80, which port is the host’s?The first: host port 8080 maps to container port 80 - 20Remove the container automatically when it exitsbash
docker run --rm alpine echo hi - 21Pass an environment variable or an env filebash
docker run -e NODE_ENV=production --env-file .env myapp - 22Open a shell in a running containerbash
docker exec -it web sh - 23Follow a container’s logsbash
docker logs -f web - 24List all containers, including stopped onesbash
docker ps -a - 25Remove unused data (stopped containers, unused networks, dangling images, build cache)bash
docker system pruneAdd-ato also remove all unused images, and--volumesfor unused anonymous volumes. - 26Named volume vs bind mountA volume is managed by Docker and survives container removal; a bind mount maps a host path into the container
- 27Mount a named volume for Postgres databash
docker run -v pgdata:/var/lib/postgresql/data postgres:17 - 28Bind-mount the current directory read-onlybash
docker run -v "$(pwd)":/app:ro myapp - 29What happens to data written inside a container without a volume?It lives in the container’s writable layer and is lost when the container is removed
- 30How do containers on the same user-defined network reach each other?By container (or Compose service) name, through Docker’s built-in DNS
- 31Default network driver for standalone containers
bridge - 32Compose v2 command to start services in the backgroundbash
docker compose up -dCompose v2 is a Docker CLI plugin:docker compose, notdocker-compose. - 33Stop and remove Compose services (and their volumes)bash
docker compose down docker compose down -v # also removes named volumes - 34Start a service only after the database is healthyyaml
services: api: depends_on: db: condition: service_healthy db: image: postgres:17 healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres"] interval: 5s - 35Does plain
depends_onwait until a service is ready?No, only until it has started. Usecondition: service_healthywith a health check - 36Compose profilesServices with
profilesonly start when that profile is enabledyamlservices: adminer: image: adminer profiles: ["debug"] # docker compose --profile debug up - 37Rebuild images and start with Composebash
docker compose up -d --build - 38Run a one-off command in a Compose servicebash
docker compose run --rm api npm test - 39Where does Compose read variable substitutions like
${TAG}from?The shell environment and a.envfile next to the compose file - 40Why use a
-slimoralpinebase image?Fewer packages mean smaller images, faster pulls and less attack surfaceAlpine uses musl libc, which some native modules don’t support. - 41Keep an image small when installing packagesCombine install and cleanup in one
RUNso deleted files never land in a layerdockerfileRUN apt-get update && apt-get install -y --no-install-recommends curl \ && rm -rf /var/lib/apt/lists/* - 42Why shouldn’t secrets go in
ENVorARG?They end up in the image metadata or history where anyone with the image can read themUse build secrets (RUN --mount=type=secret) or runtime environment variables. - 43Why pin image tags instead of using
latest?latestchanges over time, so builds aren’t reproducible; pin a version or a digest - 44Show an image’s layers and the commands that made thembash
docker history myapp:1.0 - 45Inspect a container’s configuration as JSONbash
docker inspect web - 46Copy a file out of a containerbash
docker cp web:/app/log.txt ./log.txt - 47Limit a container’s memory and CPUbash
docker run --memory=512m --cpus=1.5 myapp - 48Restart policy that brings a container back after crashes and rebootsbash
docker run -d --restart unless-stopped myapp - 49Push an image to a registrybash
docker tag myapp:1.0 ghcr.io/me/myapp:1.0 docker push ghcr.io/me/myapp:1.0 - 50Build for another CPU architecturebash
docker buildx build --platform linux/arm64 -t myapp:arm64 .
Frequently asked questions
Does this deck cover Docker Compose?
Yes: services, dependencies with health checks, profiles, rebuilds and one-off commands, using the Compose v2 docker compose command.
Is it about Kubernetes too?
No. It focuses on Docker and Compose, the foundation you need before orchestration; the Kubernetes deck picks up from there.
Which Docker version does it assume?
A current Docker Engine (27 or newer) with BuildKit and Compose v2, the defaults in Docker Desktop and recent Linux packages.
More in IT & DevOps
Linux command line
Linux commands and files for sysadmins and LPIC-1 candidates: find and grep, permissions and special bits, fstab, systemd targets, package managers, users, cron and more.
50 cardsLinux filesystem basics
Learn the Linux directory tree: what /etc, /var, /usr, /proc and /dev are for, plus passwd, shadow, fstab and hosts. Free flashcards, no signup.
50 cardsIntermediate Linux filesystem
Linux paths admins use daily: /usr/local, /var/lib, /run, /sys, /etc/skel, sudoers, Bash startup files, SSH keys, resolv.conf and /proc. Free flashcards.
50 cardsAdvanced Linux filesystem
Deeper Linux files for LPIC-1: profile.d, sudoers.d, systemd units, GRUB config, nsswitch.conf, ld.so.conf, distro logs and /lib/modules. Free flashcards.
50 cardsBash scripting
Bash scripting flashcards: shebangs, quoting, exit codes, tests, loops, functions, arrays, parameter expansion, redirection, set -euo pipefail and traps.
50 cardsVim
Learn Vim from the keyboard up: modes, motions, operators and text objects, search and :s substitutions, registers, macros, visual mode and windows.
50 cardsNetworking
Computer networking fundamentals: OSI and TCP/IP layers, TCP vs UDP, common port numbers, subnetting and CIDR, DNS, DHCP and ARP, and IPv6 basics.
50 cardsCyber security
Cyber security flashcards: the CIA triad, phishing, XSS, CSRF, SQL injection, MITM, hashing vs encryption, TLS, MFA, least privilege, OWASP and zero trust.
50 cardsKubernetes
Kubernetes fundamentals for developers and CKA or CKAD candidates: Pods, Deployments, Services, storage, probes, resources and scheduling, plus the kubectl commands you use daily.
50 cardsAWS
AWS flashcards: regions and AZs, EC2, S3 storage classes, IAM users, roles and policies, VPC networking, RDS, Lambda, CloudWatch and Route 53.
50 cardsTerraform
Terraform flashcards: HCL, providers, resources, variables and outputs, state and remote backends, plan and apply, modules, count, for_each, drift and import.
50 cards