The Magnificent Seven

[!TIP] You only need to memorize 7 commands to be productive with Docker. The other 50 are for specific use cases.

1. docker run (Create & Start)

The Swiss Army knife. It creates a container from an image and starts it.

docker run -d -p 80:80 --name my-nginx nginx
  • -d: Detached mode (run in background).
  • -p 80:80: Map Host Port 80 to Container Port 80.
  • --name: Give it a friendly name (instead of zen_einstein).
  • nginx: The image to use.

2. docker ps (List Containers)

Lists running containers.

docker ps
# CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                NAMES
# a1b2c3d4e5f6   nginx     "/docker-entrypoint.…"   10 seconds ago   Up 9 seconds    0.0.0.0:80->80/tcp   my-nginx
  • docker ps -a: List all containers (including stopped ones).

3. docker stop (Graceful Shutdown)

Sends SIGTERM to the main process (PID 1). Gives it 10 seconds to clean up, then SIGKILL.

docker stop my-nginx

4. docker rm (Remove Container)

Deletes a stopped container. Frees up disk space.

docker rm my-nginx
# To force remove a running container:
docker rm -f my-nginx

5. docker images (List Images)

Shows all images downloaded to your local cache.

docker images
# REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
# nginx         latest    605c77e624dd   2 weeks ago     141MB

6. docker rmi (Remove Image)

Deletes an image from local cache.

docker rmi nginx

7. docker exec (Enter Container)

Run a command inside a running container. Useful for debugging.

docker exec -it my-nginx bash
# You are now inside the container!
root@a1b2c3d4e5f6:/# ls /etc/nginx

8. Interactive: Terminal Simulator

Practice these commands safely in this simulated environment.

bash — 80x24
Welcome to Docker Simulator v1.0
Type 'help' for available commands. Try 'docker run nginx'!
user@host:~$

9. Cheat Sheet

Command Description Mnemonic
docker run <img > Create and Start a container Run it!
docker ps List running containers Process Status
docker exec -it <id> bash Shell into a container Execute inside
docker logs <id> View output (stdout/stderr) Show me the Logs
docker stop <id> Stop a container (SIGTERM) Stop it
docker rm <id> Delete a container Remove Container
docker rmi <img> Delete an image Remove Image