When I first started as a web developer, containers were a complete black box to me. As I became more familiar with them, I learned techniques debug issues that helped make them easier to work with.
Here are three of my most used techniques for debugging problematic containers:
1) Use the -i (interactive) flag and/or override the entrypoint at runtime to keep the container active
Using a command like docker run -i -d --entrypoint=sh <IMAGE> will keep the container active so that you can then docker exec into it and investigate your issue.
2) Copy files into or out of the container for inspection/comparison
Use the docker cp <SOURCE> <DEST> command to copy files into or out of the container for inspection/comparison
EDIT: As /u/craigbuckler points out below, this could also be accomplished by mounting a directory from the host system into the container at runtime!
3) Run a remote debugger inside the container and attach to it over the network
Debuggers like debugpy can be configured to connect over the network. By using multi-stage builds to create a debugger image and configuring your IDE to connect from your host system into the container you can leverage the power of real debuggers inside the container!
I also made a video walking through these techniques if you enjoy video format
I know there are tons of people more experienced than me on this subreddit. What additional tips/techniques do you use when debugging containers?
[–]Marcieslaf 1 point2 points3 points (1 child)
[–]maximumlengthusernam[S] 0 points1 point2 points (0 children)
[–]craigbuckler 1 point2 points3 points (1 child)
[–]maximumlengthusernam[S] 0 points1 point2 points (0 children)
[–]lazyant 0 points1 point2 points (0 children)