0

When running an app from docker, sometimes it would be nice to jump in and explore what the image looks like by cding around and view the various files and directory structure with commands like ls, as well as env or other similar commands. A bit like pry for ruby.

Does an interactive debugger exist for Docker?

stevec
  • 41,291
  • 27
  • 223
  • 311
  • 1
    `docker exec -it container-name bash` will get you a shell (assuming the image does contain bash; not all do). I'd recommend using it more as a debugger as you suggest here, and not as the main way to interact with your application. – David Maze Apr 11 '22 at 09:40
  • **`docker exec -it 5ae8669be8f8 sh`** (use `docker ps` to find the id for the container you want to shell into). – stevec Apr 12 '22 at 03:38
  • 1
    If you started the container with `docker run --name`, you can use that name in `docker exec` (and any other `docker` command) without looking up the container ID. – David Maze Apr 12 '22 at 03:40
  • @DavidMaze do you know if there's any way of getting an interactive session inside the actual Dockerfile? I'd like to jump in and tinker with things, particularly the CMD command (testing starting an app with different settings, options etc). – stevec Apr 13 '22 at 01:54
  • You can `docker run --rm -it your-image sh` to run an interactive shell instead of the normal `CMD` and debug from there. In non-BuildKit mode you can also use the hex IDs `docker build` prints out along the way as `docker run` image IDs for this sort of debugging. – David Maze Apr 13 '22 at 10:36
  • 1
    I've requested an edit of the question. I'll comment why here as well: The user wants an interactive debugger that attaches to an application running in the container. All the blurb made it confusing. Answer: Visual Studio Code does it: https://code.visualstudio.com/docs/containers/debug-common – RobMac Aug 05 '22 at 21:24

0 Answers0