# 6 Ways to Debug a Failing Docker Container

DevFeed: [6 Ways to Debug a Failing Docker Container](<https://devfeed.tech/articles/6-ways-to-debug-an-exploding-docker-container-19050.md>)

Original publisher: [Read original article](<https://httptoolkit.com/blog/debug-failing-docker-container/>)

Author: HTTP Toolkit; Tim Perry

Published: 2023-10-31T14:00:00Z

Content type: tutorial

Language: en

Sources: [HTTP Toolkit](<https://devfeed.tech/sources/http-toolkit.md>)

Topics: [Docker](<https://devfeed.tech/topics/docker.md>), [debugging](<https://devfeed.tech/topics/debugging.md>), [container](<https://devfeed.tech/topics/container.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>)

Tags: [command-line](<https://devfeed.tech/tags/command-line.md>), [container](<https://devfeed.tech/tags/container.md>), [debugging](<https://devfeed.tech/tags/debugging.md>), [docker](<https://devfeed.tech/tags/docker.md>), [errors](<https://devfeed.tech/tags/errors.md>), [logs](<https://devfeed.tech/tags/logs.md>), [metrics](<https://devfeed.tech/tags/metrics.md>)

## AI overview

A tutorial on diagnosing Docker containers that fail to start or behave unexpectedly. It covers commands for viewing logs and resource usage, copying files, opening a shell, and inspecting a stopped container by creating an image with a different command.

## Source excerpt

Everything crashes. Sometimes things crash when they're running inside a Docker container though, and then all of a sudden it can get much more difficult to work out why, or what the hell to do next. Docker's great, but it's an extra layer of complexity that means you can't always easily poke your app up close any more, and that can really hinder debugging when your container fails to start or breaks in unusual ways. If you're stuck in that situation, here are my goto debugging commands to help you get a bit more information on exactly what's up: docker logs <container_id> Hopefully you've already tried this, but if not: start here. This'll give you the full STDOUT and STDERR command-line output from the command that was run initially in your container. You can also use docker attach <container id> to stream the live logs from an active container, if you want to keep an eye on the output as it runs. docker stats <container_id> If you just need to keep an eye on the metrics of your container to work out what's gone wrong, docker stats can help: it'll give you a live stream of resource usage, so you can see just how much memory you've leaked so far and easily spot if your CPU usage is way out of control. docker cp <container_id>:/path/to/useful/file /local-path Often just getting hold of more log files is enough to sort you out. If you already know what you want, docker cp has your back: copy any file from any container back out onto your local machine, so you can examine it in depth (especially useful analysing heap dumps). docker exec -it <container_id> /bin/bash Next up, if you can run the container (if it's crashed, you can restart it with docker start <container_id>) then you can use this command to oppen a command line shell inside the container directly, and start digging around for further details by hand. docker commit <container_id> my-broken-container && docker run -it my-broken-container /bin/bash Can't start your container at all? If your container starts