Skip to main content

Command Palette

Search for a command to run...

Docker Debugging Commands

Published
3 min read
Docker Debugging Commands
R

I'm a results-driven professional skilled in both DevOps and Web Development. Here's a snapshot of what I bring to the table:

💻 DevOps Expertise:

  • AWS Certified Solutions Architect Associate: Proficient in deploying and managing applications in the cloud.
  • Automation Enthusiast: Leveraging Python for task automation, enhancing development workflows.

🔧 Tools & Technologies:

  • Ansible, Terraform, Docker, Prometheus, Kubernetes, Linux, Git, Github Actions, EC2, S3, VPC, R53 and other AWS services.

🌐 Web Development:

  • Proficient in HTML, CSS, JavaScript, React, Redux-toolkit, Node.js, Express.js and Tailwind CSS.
  • Specialized in building high-performance websites with Gatsby.js.

Let's connect to discuss how my DevOps skills and frontend expertise can contribute to your projects or team. Open to collaboration and always eager to learn!

Aside from my work, I've also contributed to open-source projects, like adding a feature for Focalboard Mattermost.

Debugging Docker containers can be challenging, but with the right commands and techniques, you can efficiently troubleshoot issues. Here's a detailed guide on essential Docker debugging commands that every developer should know.

Container Inspection and Logs

docker ps

The most basic debugging starts with checking container status:

docker ps            # List running containers
docker ps -a         # List all containers, including stopped ones

docker logs

Investigate container logs to understand what's happening inside:

docker logs <container_id>              # View container logs
docker logs -f <container_id>           # Follow log output in real-time
docker logs --tail 100 <container_id>   # View last 100 log lines
docker logs --since 1h <container_id>   # View logs from last hour

Interactive Debugging

docker exec

Execute commands inside a running container:

docker exec -it <container_id> /bin/bash    # Start interactive shell
docker exec -it <container_id> /bin/sh      # For Alpine-based images
docker exec <container_id> ps aux           # List running processes

docker inspect

Get detailed information about containers:

docker inspect <container_id>                # View all container metadata
docker inspect --format='{{.State.Status}}' <container_id>    # Check container status
docker inspect --format='{{.NetworkSettings.IPAddress}}' <container_id>    # Get container IP

Resource Monitoring

docker stats

Monitor container resource usage:

docker stats                    # Monitor all containers
docker stats <container_id>     # Monitor specific container

Network Debugging

docker network

Inspect and troubleshoot network connections:

docker network ls              # List all networks
docker network inspect <network_name>    # Inspect network details
docker network connect <network_name> <container_id>    # Connect container to network

Image Debugging

docker history

Understand how an image was built:

docker history <image_name>    # View image layer history

docker diff

Check what has changed in container filesystem:

docker diff <container_id>     # Show changed files in container

Advanced Debugging Techniques

Using Debug Mode

Enable debug mode for more detailed logs:

dockerd --debug               # Start Docker daemon in debug mode

Health Checks

Monitor container health status:

docker inspect --format='{{.State.Health.Status}}' <container_id>

Best Practices for Docker Debugging

  1. Keep containers focused and minimal to reduce debugging complexity

  2. Use appropriate logging drivers and configure log rotation

  3. Implement health checks in your Dockerfile

  4. Monitor resource usage regularly

  5. Maintain proper container naming conventions

  6. Document common debugging procedures for your team

Troubleshooting Common Issues

Container Won't Start

docker events              # Monitor Docker events in real-time
docker logs <container_id> # Check startup logs

Network Connectivity Issues

docker network inspect bridge    # Inspect default network
docker exec <container_id> ping <destination>    # Test connectivity

Remember that preventing issues is often better than debugging them. Implement proper monitoring, logging, and testing strategies in your Docker deployments to catch problems early and maintain healthy container environments.

More from this blog

Rohit's Blog

92 posts

🚀 DevOps Engineer | Fullstack Developer

Find interesting blogs about Devops, Cloud Computing and Web development related topics