During the Dockerfile's development, and later it's deployment, the need for debugging might arise. Sometimes it would be nice to have a possibility to attach to a newly deployed, running container, to do the troubleshooting, in case if something inside of a container happened unexpected.

First, check what Docker version you are using, because, since version >=0.9 the attach procedure has changed - the use of lxc-attach app won't work, because of dropped LXC's userland tools. Instead, for the later Docker's there is a dedicated tool called nsenter, which is shipped by the util-linux (ver. >=2.24) package.

Using nsenter to attach to a running Docker container is a quite simple task.1) Find the PID of the first process of a running container.

1.2) Export PID env variable for later usage, which will contain the 1st PID from the container (note: PID number "1" in the container itself but from the outside of a container this will be probably a quite high, positive value...):