Open a shell in a running container

Poke around inside a container to see what it actually looks like in there.

SNP 046 #B27 Filed docker cmd

shell
docker exec -it my-container sh

-i keeps stdin open, -t gives you a terminal. Use bash if the image has it; Alpine-based ones usually only have sh.

With compose you use the service name instead of the container name:

shell
docker compose exec app sh

To run a single command and leave, drop the -it and the shell:

shell
docker exec my-container cat /etc/hosts