Access a Docker container without ssh
Quick tip to access a container without SSH.
Let’s run a simple memcached server:
$ sudo docker run -d -p 11211 bacongobbler/memcached memcached /usr/bin/memcached -m 64 -p 11211 -u memcache -l 0.0.0.0 |
$ sudo docker ps |
This is important you must grab the PID of the first running process inside the container, the one with PID 1. So on the host run:
root@docker:~# ps faux |grep memcached |
The nsenter
command is part of the util-linux
package, however it only appeared during the 2.23 release.
Unfortunately, if you are running Ubuntu, the latest version available is 2.20, so you have to install the last version manually.
$ wget https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.tar.bz2 |
Now let’s enter the container:
$ sudo nsenter -m -u -i -n -p -t 29123 /bin/sh |
Handy script:
|
Use it like this: ./enter-container <container id>
.
Tada!
Comments