Dockerfile Overview
A concise reference for common Docker commands with short descriptions.
In general the Dockerfile or docker-compose.yml file are stored in the root directory of the project.
List all docker containers on your machine
docker ps -aList all running docker containers on your machine
docker psList all docker volumes
docker volume lsRemove specific volume
docker volume rm <volume-name>Remove all unused volumes
docker volume pruneClear cached build layers and force docker to rebuild every layer (if you get an error while building a docker image)
docker builder prune -f- This also frees up disk space
Example Dockerfile for the offical Hello World Image
# Use the official lightweight Hello World image
FROM hello-worldBuild Images
Build a Docker image from a Dockerfile
docker build -f Dockerfile.app -t my-app .Run Containers
Run a container in detached mode, restart automatically, and map ports
docker run -d --restart=always --name my-app -p 3000:3000 my-appRun multiple containers on different ports
docker run -d --restart=always --name app1 -p 3001:3000 app1docker run -d --restart=always --name app2 -p 3002:3000 app2Networks
Create a custom network
docker network create my-networkConnect a container to a network
docker network connect my-network my-appInspect a container’s IP on the network
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' my-appContainer Info
List running containers
docker psList all containers including stopped
docker ps -aStop Containers
Stop by container name
docker stop my-appStop by container ID
docker stop <container-id>Stop all running containers
docker stop $(docker ps -q)Remove Containers
Remove a specific container
docker rm my-appRedeploy Container
Stop container
docker stop my-appRemove container
docker rm my-appBuild container
docker build -f Dockerfile.app -t my-app .Run container
docker run -d --name my-app --network my-network -p 3000:3000 my-appTroubleshoot Docker
If you have errors while building docker images or containers try theses commands
Yes. The commands you already used remove almost everything unused, but here’s a complete breakdown:
- Remove all stopped containers, unused networks, dangling images, and build cache:
docker system prune --volumes --all --force--allremoves all unused images, not just dangling ones.--volumesremoves unused volumes.--forceskips confirmation.
- Remove all builder cache (used in multi-stage builds):
docker builder prune --all --force- Optional: Remove unused images individually:
docker images -a # lists all images
docker rmi <image_id>- Optional: Remove all stopped containers individually:
docker ps -a # lists all containers
docker rm <container_id>- Optional: Remove all unused volumes:
docker volume ls -qf dangling=true
docker volume rm $(docker volume ls -qf dangling=true)The two commands you already ran are sufficient to fully clean the environment, including caches that could cause cross-platform module issues.
Created: 20.10.2025
Last Updated: 20.10.2025