How would you troubleshoot a container if it is not running? #
-
Missing or Incorrect Environment Variables: Container fails due to missing or incorrect environment variables
-
Incorrect Container Command or Entrypoint: Container exits immediately after starting or fails to perform expected tasks
-
Volume Issues: Container startup fails due to volume mount errors or permissions
-
Inspect Container Logs: To inspect logs for the container to understand why it might have failed to start
docker logs [container_id]
-
Inspect Container Configuration: Retrieve details on container settings, environment variables, volumes, and networking
docker inspect [container_id]
-
Review Container Events: Monitor real-time events for errors or warnings during container startup
docker events -f [container_id] --since 2m
-
Verify Resource Availability: Ensure adequate CPU, memory, and disk space for container operation
docker stats [container_id]
-
Check Docker Engine Logs: Review Docker engine logs for system-level issues that may affect container startup
journalctl -u docker.service
How do you get all the system-level information about docker? Like events, disk space, caching, etc.. #
-
Display system-wide information about Docker installation, including number of containers, images, and storage driver details
docker info
-
Show Docker disk usage, including total and used space for images, containers, and volumes
docker system df
-
Monitor Docker events in real-time, such as container starts/stops, image pulls, and network changes
docker events
-
Display real-time CPU, memory, and network usage statistics for running containers
docker stats [container_id]
-
Show the history of an image, including commands and metadata used to create each layer
docker history [image_name]
-
Return low-level information about Docker objects, such as containers, images, networks, and volumes
docker inspect [object_name]
-
Remove unused data, such as stopped containers, dangling images, and unused networks and volumes
docker system prune
-
Remove unused images
docker image prune
-
Remove unused containers
docker container prune
-
Remove unused networks
docker network prune
-
Get real-time events from the Docker daemon, similar to
docker events
docker system events