Introduction#
Docker is an open-source platform that allows you to package applications and their dependencies into portable containers.
Containers are lightweight, consistent, and reproducible environments, making Docker a core technology in DevOps, CI/CD pipelines, and Infrastructure as Code (IaC) practices.
With Docker, you can:
- Run applications in isolated environments.
- Ensure the same behavior across development, testing, and production.
- Easily scale services and orchestrate multiple containers.
This article will define Docker’s key vocabulary, explain prerequisites, and provide a cheat sheet for common commands and workflows.
Vocabulary#
Core Concepts#
- Container : A lightweight, standalone environment that packages an application with its dependencies.
- Image : A read-only template used to create containers.
- Dockerfile : A text file with instructions to build a Docker image.
- Registry : A repository for storing and distributing Docker images (Docker Hub, self-hosted registry).
- Container Runtime : Software that runs containers (Docker Engine).
- Volume : A persistent storage mechanism for containers.
- Network : Defines how containers communicate with each other or the outside world.
- Docker Compose : A tool to define and run multi-container applications using YAML.
Docker Objects#
- Container ID / Name : Unique identifier for running containers.
- Tag : A label for identifying image versions (
:latest,:v1.0). - Layer : Each instruction in a Dockerfile creates a new image layer.
- Port Mapping : Exposing container ports to the host (
-p hostPort:containerPort). - EntryPoint : The default command executed when a container starts.
- CMD : Default arguments for the container entrypoint.
- Environment Variables : Variables passed to containers to configure runtime behavior.
Docker Commands#
- docker build : Build an image from a Dockerfile.
- docker run : Create and start a container from an image.
- docker ps : List running containers.
- docker stop / docker kill : Stop a running container.
- docker rm : Remove a stopped container.
- docker rmi : Remove an image.
- docker logs : View container logs.
- docker exec : Execute a command inside a running container.
- docker-compose up / down : Start or stop multi-container applications.
- docker system prune : Remove all unused containers, networks and images
Dockerfile Instructions#
- FROM : Base image to use.
- RUN : Execute commands to install packages or configure image.
- COPY / ADD : Copy files from host into the image.
- WORKDIR : Set working directory for subsequent instructions.
- EXPOSE : Declare which ports the container will listen on.
- ENV : Set environment variables.
- ENTRYPOINT : Define container entrypoint.
- CMD : Default arguments for ENTRYPOINT.
Prerequisites#
- Docker Engine installed on your host (Linux, macOS, or Windows).
- Docker Compose installed if using multi-container setups.
- Familiarity with command-line usage and basic Linux commands.
- Optional: A private registry if you plan to host your own images (gitea or nexus for instance).
Docker Cheat Sheet#
| Command | Purpose | Example |
|---|---|---|
docker build -t <myapp:1.0> . | Build image from Dockerfile | docker build -t myapp:1.0 |
docker tag myapp:1.0 myregistry.local/myapp:1.0 | Tag local image | docker tag myapp:1.0 myregistry.local/myapp:1.0 |
docker push myregistry.local/myapp:1.0 | Push image to registry | docker push myregistry.local/myapp:1.0 |
docker run -d -p 8080:80 myapp:1.0 | Run container detached | docker run -d -p 8080:80 myapp:1.0 |
docker ps | List running containers | |
docker stop <container> | Stop container | docker stop nginx |
docker rm <container> | Remove container | docker rm nginx |
docker rmi <image>:<versions | Remove image | docker rmi nginx:1.0 |
docker logs <container> | View container logs | docker logs nginx |
docker exec -it <container> <command> | Execute command in container | docker exec -it nginx sh |
docker compose up -d | Start multi-container app | |
docker compose down | Stop multi-container app | |
docker system prune | Stop multi-container app |

