Docker Commands
Essential Docker commands for building, running, and managing containers.
Images
docker build -t myapp .Build an image from Dockerfile in current directory
docker imagesList all local images
docker pull nginx:latestPull an image from Docker Hub
docker rmi image_nameRemove a local image
docker tag myapp user/myapp:v1Tag an image for pushing to registry
Containers
docker run -d -p 3000:3000 myappRun container in detached mode with port mapping
docker run -it ubuntu bashRun container interactively with shell access
docker psList running containers
docker ps -aList all containers including stopped ones
docker stop container_idGracefully stop a running container
docker rm container_idRemove a stopped container
docker exec -it container_id bashOpen a shell inside a running container
Docker Compose
docker compose up -dStart all services in the background
docker compose downStop and remove all containers and networks
docker compose logs -fFollow logs from all services
docker compose build --no-cacheRebuild images without using cache
docker compose psList running compose services
Volumes & Networks
docker volume create mydataCreate a named volume for persistent storage
docker volume lsList all volumes
docker network create mynetCreate a custom bridge network
docker run --network mynet myappRun container on a specific network
Cleanup & Debug
docker system prune -aRemove all unused images, containers, and networks
docker logs container_idView container logs
docker inspect container_idView detailed container/image metadata as JSON
docker statsLive stream of container resource usage (CPU, memory)