Common Docker Commands
# List all running containers
docker ps
# List all containers (including stopped)
docker ps -a
# Start a container
docker start <container_name>
# Stop a container
docker stop <container_name>
# Restart a container
docker restart <container_name>
# Remove a container
docker rm <container_name>
# List images
docker images
# Pull an image
docker pull ubuntu:latest
# Remove an image
docker rmi ubuntu:latest
# Build an image from a Dockerfile
docker build -t myimage:latest .
# Show logs for a container
docker logs <container_name>
# Tail logs (live updates)
docker logs -f <container_name>
# Execute a command inside a running container
docker exec -it <container_name> bash
# Inspect container details (network, volumes, etc)
docker inspect <container_name>
# Show logs for a container
docker logs <container_name>
# Tail logs (live updates)
docker logs -f <container_name>
# Execute a command inside a running container
docker exec -it <container_name> bash
# Inspect container details (network, volumes, etc)
docker inspect <container_name>
# Start services in the background
docker compose up -d
# Pull latest images for all services
docker compose pull
# Stop all services
docker compose down
# Rebuild and start
docker compose up --build
# View logs from all services
docker compose logs -f
# Remove stopped containers
docker container prune
# Remove unused images
docker image prune
# Remove everything not used (containers, networks, images, volumes)
docker system prune -a
# Run a one-off container
docker run --rm -it alpine sh
# Copy files from container to host
docker cp <container_name>:/path/in/container /path/on/host