Code Reference

Getting Started with Docker

Docker · Reference cheat sheet

Getting Started with Docker

Docker · Reference cheat sheet


📋 Overview

Docker packages apps and dependencies into images and runs them as containers. Use it for reproducible environments, local stacks, and deployment units.

🔧 Core concepts

IdeaMeaning
ImageImmutable filesystem + metadata template
ContainerRunning (or stopped) instance of an image
DockerfileBuild recipe for an image
RegistryImage store (Docker Hub, GHCR, …)
ComposeMulti-container app definition
CommandPurpose
docker versionClient/server versions
docker pullDownload image
docker runCreate + start container
docker psList running containers
docker buildBuild from Dockerfile

💡 Examples

Run nginx:

docker run --rm -p 8080:80 nginx:alpine

Build and run:

docker build -t myapp:dev .
docker run --rm -p 9000:9000 myapp:dev

Shell into a container:

docker exec -it <container> sh

⚠️ Pitfalls

  • Binding only to container localhost is fine; publishing ports needs -p host:container.
  • Data in the writable container layer is lost when the container is removed — use volumes.
  • Running as root inside images increases risk — prefer non-root users in production images.

On this page