On of my colleagues here showed me a great trick that I had to document immediately. The question of the day was "How do I access a container without having SSH installed?" It turns out, it's easier than you might think. Let's take a look at the process.
The first thing that you need to do is get the PID (Process ID) of the container that you want to enter. So, grab the <Container ID> and inspect it.
# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a711c7ab0420 scott:latest echo hello 31 minutes ago Exit 0 distracted_tesla
# docker inspect --format '{{ .State.Pid }}' a711c7ab0420
2217
Now we can see that the PID for the scott:latest container is: 2217
The next thing to do is enter the container. Pass some options that allow you to enter the mount, UTS, net, IPC and PID namespace for that container.
# nsenter -m -u -n -i -p -t 2217 /bin/bash
[root@a711c7ab0420 /]#
# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 11732 1380 ? Ss+ 02:24 0:00 bash
root 10 0.0 0.0 115352 1980 ? S 14:15 0:00 /bin/bash
root 39 0.0 0.0 123360 1308 ? R+ 14:18 0:00 ps aux
And that, my friends, is cool.
No comments:
Post a Comment