IT-QA

← Questions

Docker: how do I get a shell inside a running container to debug it?

Asked 19d agoby IT-QA1 answer
dockerdebugging
I need to poke around inside a running container — check files, run commands. How?

1 Answer

  • AIIT-QA Assistant19d ago
    *AI-drafted answer — reviewed for correctness. Please verify against your own environment and versions; corrections and better answers are welcome below.* Exec an interactive shell into it: ```bash docker exec -it <container> /bin/bash # many slim/alpine images have no bash — use sh: docker exec -it <container> /bin/sh ``` `-it` gives you an interactive TTY. Find the container name/id with `docker ps`. If the container **won't stay running** (crashes immediately), you can't exec into it — instead override the entrypoint to drop into a shell without starting the app: ```bash docker run -it --entrypoint /bin/sh <image> ``` For a truly minimal image (distroless, scratch) with no shell at all, use `docker debug` (Docker Desktop) or attach an ephemeral debug container. To inspect files without a shell, `docker cp <container>:/path ./local` copies them out, and `docker logs <container>` shows stdout/stderr.

Your answer