Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

Docker & Containers Quick Reference cheat sheet - grade 10-12

Click image to open full size

Docker is a tool for packaging an application with the files, settings, and dependencies it needs to run. This cheat sheet helps students remember the most common container concepts and commands without searching documentation. It is useful for programming classes, web development projects, and deployment practice.

Containers make it easier to run the same app on different computers with fewer setup problems.

The most important ideas are images, containers, Dockerfiles, volumes, ports, and Compose files. An image is a reusable template, while a container is a running instance of that image. Dockerfiles describe how to build images, and docker-compose.yml files describe multi-container apps.

Commands like docker build, docker run, docker ps, and docker compose up control the main container workflow.

Key Facts

  • An image is a read-only template, and a container is a running instance created from an image.
  • Build an image from the current folder with docker build -t app-name .
  • Run a container in the background with docker run -d --name my-app -p 8080:80 app-name.
  • List running containers with docker ps, and list all containers with docker ps -a.
  • Stop a container with docker stop container-name, and remove it with docker rm container-name.
  • Map ports using hostPort:containerPort, such as -p 8080:80, which sends host port 8080 traffic to container port 80.
  • Persist data with a volume using docker run -v my-data:/app/data image-name.
  • Start services from a Compose file with docker compose up, and stop them with docker compose down.

Vocabulary

Container
A lightweight running environment that packages an application with the files and dependencies it needs.
Image
A reusable blueprint used to create one or more containers.
Dockerfile
A text file containing step-by-step instructions for building a Docker image.
Volume
A storage location managed by Docker that keeps data even after a container is removed.
Port Mapping
A rule that connects a port on the host computer to a port inside a container.
Docker Compose
A tool for defining and running multi-container applications using a docker-compose.yml file.

Common Mistakes to Avoid

  • Confusing an image with a container is wrong because an image is the template, while a container is the running or stopped instance made from it.
  • Forgetting the final dot in docker build -t app-name . is wrong because the dot tells Docker to use the current folder as the build context.
  • Mapping ports backward is wrong because -p 8080:80 means host port 8080 connects to container port 80, not the other way around.
  • Storing important data only inside a container is risky because removing the container can delete that data unless a volume is used.
  • Editing files inside a running container as the main workflow is a mistake because those changes are usually not saved in the image or project source files.

Practice Questions

  1. 1 Write the command to build an image named school-api from the current directory.
  2. 2 A web server listens on port 3000 inside a container. Write a docker run port option that makes it available on host port 8080.
  3. 3 A container is named test-db. Write the commands to stop it and then remove it.
  4. 4 Explain why a team might use Docker Compose instead of starting each container with separate docker run commands.