Docker Compose Tip #34: Debugging with exec vs run

Know the difference between exec and run! Each has its place in your debugging toolkit. The key difference exec: Runs commands in an existing container run: Creates a new container # Exec: enters running container docker compose exec web bash # Run: starts new container docker compose run web bash When to use exec Use exec for debugging running services: # Debug a running web server docker compose exec web bash # Check logs inside container docker compose exec web tail -f /var/log/app.log # Run database queries docker compose exec db psql -U postgres # Check process list docker compose exec web ps aux # Test connectivity from inside docker compose exec web curl http://api:3000/health Important: Container must be running! ...

March 2, 2026 · 3 min · 636 words · Guillaume Lours