You've googled "docker command to remove stopped containers" at 2 AM. This post ends that cycle โ with diagrams, not just a wall of text โ for beginners and pros alike.
๐ง Core Concepts
| Term | What it is |
|---|---|
| Image | Read-only blueprint of your app โ the recipe. |
| Container | A running instance of an image โ the cooked dish. |
| Registry | Remote image storage, e.g. Docker Hub. |
| Volume | Persistent storage that survives container deletion. |
| Network | Virtual wire letting containers talk by name. |
Try this now: docker run -d -p 8080:80 nginx, then open localhost:8080. That's a real server running in a container.
๐ฆ Images
๐ข Beginner ๐ต Intermediate ๐ฃ Advanced
| Command | Purpose | Docs | |
|---|---|---|---|
| ๐ข | docker build -t app . |
Builds an image from a Dockerfile | build |
| ๐ต | docker build --no-cache |
Rebuilds ignoring cached layers | build |
| ๐ข | docker images |
Lists all local images | ls |
| ๐ข | docker rmi app |
Deletes a local image | rm |
| ๐ต | docker image prune |
Removes dangling, untagged images | prune |
| ๐ต | docker image prune -a |
Removes all unused images | prune |
| ๐ข | docker pull nginx |
Downloads an image from a registry | pull |
| ๐ต | docker push user/app |
Uploads an image to a registry | push |
| ๐ข | docker tag app user/app |
Renames or versions an image | tag |
| ๐ฃ | docker inspect app |
Shows full image metadata as JSON | inspect |
Further reading: Docker cheat sheet ยท Collabnix ยท HN
๐ Containers
| Command | Purpose | Docs | |
|---|---|---|---|
| ๐ข | docker run nginx |
Creates and starts a container | run |
| ๐ข | docker run -d nginx |
Runs a container in the background | run |
| ๐ข | docker run --name web nginx |
Runs a container with a custom name | run |
| ๐ข | docker run -p 8080:80 nginx |
Maps a host port to a container | run |
| ๐ต | docker run -it ubuntu bash |
Runs a container with a live shell | run |
| ๐ข | docker ps |
Lists running containers | ls |
| ๐ข | docker ps -a |
Lists all containers, including stopped | ls |
| ๐ข | docker stop web |
Gracefully stops a container | stop |
| ๐ข | docker start web |
Restarts a stopped container | start |
| ๐ข | docker restart web |
Stops and starts a container again | restart |
| ๐ข | docker rm web |
Deletes a stopped container | rm |
| ๐ต | docker rm -f web |
Force-removes a running container | rm |
| ๐ต | docker exec -it web bash |
Opens a shell inside a running container | exec |
| ๐ข | docker logs web |
Shows a container's log output | logs |
| ๐ข | docker logs -f web |
Streams logs live | logs |
Further reading: Running containers ยท Collabnix ยท HN
๐งน Cleanup
| Command | Purpose | Docs | |
|---|---|---|---|
| ๐ต | docker container prune |
Removes all stopped containers | prune |
| ๐ต | docker network prune |
Removes unused networks | prune |
| ๐ฃ | docker volume prune |
Removes unused volumes โ check data first | prune |
| ๐ฃ | docker system prune -a |
Removes all unused images/containers/networks | prune |
| ๐ฃ | docker system prune -a --volumes |
Same, plus wipes volumes โ irreversible | prune |
| ๐ต | docker system df |
Shows Docker's disk usage | df |
| ๐ต | docker system df -v |
Shows detailed per-item disk usage | df |
| ๐ฃ | docker kill $(docker ps -q) |
Force-stops every running container | kill |
Further reading: System prune docs ยท Collabnix ยท HN
๐ Networking & Volumes
Containers on the same custom network resolve each other by name โ no hardcoded IPs.
| Command | Purpose | Docs | |
|---|---|---|---|
| ๐ข | docker network ls |
Lists all networks | ls |
| ๐ต | docker network create my-net |
Creates a custom bridge network | create |
| ๐ต | docker network connect my-net web |
Attaches a container to a network | connect |
| ๐ฃ | docker network inspect my-net |
Shows subnet, driver, connected containers | inspect |
| ๐ข | docker volume create data |
Creates a persistent volume | create |
| ๐ข | docker volume ls |
Lists all volumes | ls |
| ๐ต | docker run -v data:/app nginx |
Mounts a named volume | run |
| ๐ต | docker run -v $(pwd):/app nginx |
Bind-mounts a local folder | run |
Further reading: Networking overview ยท Collabnix ยท HN
๐งฉ Compose
Compose replaces five docker run commands with one YAML file.
| Command | Purpose | Docs | |
|---|---|---|---|
| ๐ข | docker compose up |
Starts all services in docker-compose.yml | up |
| ๐ข | docker compose up -d |
Starts services in the background | up |
| ๐ข | docker compose down |
Stops and removes Compose containers | down |
| ๐ต | docker compose down -v |
Same, plus deletes named volumes | down |
| ๐ข | docker compose logs -f |
Streams logs from all services | logs |
| ๐ต | docker compose up --build |
Rebuilds images before starting | up |
Further reading: Compose CLI reference ยท Collabnix ยท HN
๐ ๏ธ Debugging
| Command | Purpose | Docs | |
|---|---|---|---|
| ๐ต | docker stats |
Shows live CPU/memory usage per container | stats |
| ๐ข | docker cp web:/app/f.json . |
Copies a file between host and container | cp |
| ๐ฃ | docker history app |
Shows every layer used to build an image | history |
Further reading: Docker CLI reference ยท Collabnix ยท HN
โ Key Takeaways
- Images are blueprints, containers are running instances โ everything traces back to this.
-
docker runis your most-used command โ master-d -p -v --name -itfirst. - Cleanup isn't optional. Make
docker system prune -a --volumesa habit. - Custom networks give free DNS โ containers resolve each other by name.
- Compose replaces a wall of
docker runcommands with one YAML file. -
docker logs,exec, andinspectare your debugging trio. - Bookmark this post โ you don't need to memorize all 50.
๐ฌ What Should I Cover Next?
Vote in the comments: Compose deep dive ยท Dockerfile best practices ยท Advanced networking ยท Docker security ยท Docker + Kubernetes. Tell me which and it's next.
Tags: docker devops containers beginners
Hashtags: #Docker #DevOps #CloudNative #100DaysOfCode #PlatformEngineering #Kubernetes #BuildInPublic
Mentions: @Docker @dev_community @github @DockerCon
โ๏ธ About the Author
Padhmeni Priya R R โ Bioinformatics Master's grad working as a research scientist on cutting-edge variant analysis tools, endlessly curious about technology and AI-driven innovation.
๐ linkedin.com/in/padhmeni
Drop a ๐ณ if this saved you a search, and tell me what to cover next.


Top comments (0)