How to enter in a Docker container already running with a new TTY

Programster picture Programster · Jan 5, 2014 · Viewed 420.2k times · Source

I have a container that is running the Apache service in the foreground. I would like to be able to access the container from another shell in order to "poke around" inside it and examine the files. At the moment, if I attach to the container, I am left looking at the Apache daemon and cannot run any commands.

Is it possible to attach another tty to a running container? Possibly, I can take advantage of the fact that Docker is actually just wrapping around LXC containers? I have tried sudo lxc-console -n [container-id] -t [1-4] but it appears that only one tty is made available and that is the one running the apache daemon. Perhaps there is a way to enable multiple lxc consoles during the build?

I would rather not configure and build the container with an openssh service if possible.

Answer

Michael_Scharf picture Michael_Scharf · Oct 21, 2014

With docker 1.3, there is a new command docker exec. This allows you to enter a running container:

docker exec -it [container-id] bash