Checking container status
Bash
# Running containers
docker ps
# Including stopped containers
docker ps -a
# Real-time resource usage monitoring
docker stats
# A specific container only
docker stats my_appViewing logs
Bash
# Full logs
docker logs my_app
# Last 100 lines
docker logs --tail 100 my_app
# Follow in real time
docker logs -f my_app
# Include timestamps
docker logs -t my_app
# Logs since a specific time
docker logs --since "2024-01-15T10:00:00" my_appAccessing the container
Bash
# Open a shell (use sh if bash is not available)
docker exec -it my_app bash
docker exec -it my_app sh
# Run a single command
docker exec my_app cat /etc/nginx/nginx.conf
# Connect as root (for permission debugging)
docker exec -u root -it my_app bash
# Check environment variables
docker exec my_app envQuerying details with inspect
Bash
# Full information (JSON)
docker inspect my_app
# Extract a specific field
docker inspect -f '{{.State.Status}}' my_app
docker inspect -f '{{.NetworkSettings.IPAddress}}' my_app
docker inspect -f '{{range .Mounts}}{{.Source}} -> {{.Destination}}{{"
"}}{{end}}' my_app
# List of environment variables
docker inspect -f '{{range .Config.Env}}{{.}}{{"
"}}{{end}}' my_appWhen a container exits immediately
Bash
# Check the exit code
docker inspect my_app | grep -A5 '"State"'
# View logs of a crash-looping container
docker logs my_app 2>&1 | tail -50
# Override entrypoint to get a shell
docker run -it --entrypoint sh my_image:latest
# Copy a file from a stopped container
docker cp dead_container:/app/error.log ./error.logNetwork debugging
Bash
# List container networks
docker network ls
# Network details (which containers are connected)
docker network inspect bridge
# Ping another container from a container (use the container name)
docker exec my_app ping db
# Check DNS resolution
docker exec my_app nslookup db
# Check listening ports
docker exec my_app ss -tlnpAnalyzing image layers
Bash
# Check size per layer
docker history my_image:latest
# Detailed layer information
docker history --no-trunc my_image:latestEditorial note
AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us
Topic-related official docs (auto-linked · not per-claim sources)Docker documentation ↗
Questions & answers
Ask a question about this guide. We'll review and reply.