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.
You should use Jérôme Petazzoni's tool called 'nsenter' to enter a container without using SSH. See: https://github.com/jpetazzo/nsenter
Install with simply running:
docker run -v /usr/local/bin:/target jpetazzo/nsenter
Then use the command
docker-enter <container-id>
to enter the container.Update
As of docker 0.9, for the steps below to now work, one now has to update the
/etc/default/docker
file with the'-e lxc'
to the docker daemon startup option before restarting the daemon (I did this by rebooting the host).This is all because...
source
Please note that this will prevent the new host only networking optional feature of docker 0.11 from "working" and you will only see the loopback interface. bug report
It turns out that the solution to a different question was also the solution to this one:
Update: You will soon need to use
ps --no-trunc
instead ofps -notrunc
which is being deprecated.Find the full container ID
Enter the lxc attach command.
Top shows my apache process running that docker started.
The "nsinit" way is:
install nsinit
from inside the container:
from outside:
use it
nsenter
does that. However I also needed to enter a container in a simple way and nsenter didn't suffice for my needs. It was buggy in some occasions (black screen plus -wd flag not working). Furthermore I wanted to login as a specific user and in a specific directory.I ended up making my own tool to enter containers. You can find it at: https://github.com/Pithikos/docker-enter
Its usage is as easy as
Will take you to the containers console.
With docker 1.3, there is a new command
docker exec
. This allows you to enter a running docker: