Debug Your Container by Overriding the Command

DZone 's Guide to

Debug Your Container by Overriding the Command

A quick and simple how-to.

Free Resource

The main problem with docker on debugging has to do with images that already have the CMD command specified.

If something goes wrong and has to do with the filesystem, or some commands that should have taken effect and they did not you need to do some troubleshooting.

Overriding the command which is executed should be helpful. I do this all the time on custom images since I need some bash in order to be able to troubleshoot.

Supposing I need to troubleshoot something on the default Nginx image.

Then the Nginx image should run like this.

docker run --rmnginx

Now instead of running our server, we shall override the command with a bash session (enter a shell by executing /bin/sh).

docker run --rm-it --entrypoint "/bin/sh"nginx

If you also want to pass arguments to the executable specified there is also another workaround.

docker run --rm-it --entrypoint "ls"nginx -l
docker ,container ,tutorial

Published at DZone with permission of Emmanouil Gkatziouras , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}