Accessing docker container filesystem

I have learned of this method on a post by Rory McCune which is part of his series of posts on containerization. The series has some good quality content and at the time of writing this, still ongoing. Go check it out!

How

Each running container is an OS processes, therefore we can expect to see its filesystem somewhere inside the /proc folder.

So basically, we need to obtain the container PID and have access to the proc folder (depending on your system you might need to have root permissions).

To get the PID of any running container you need to obtain the container ID, which can be done with:

docker ps

Search on the output rows for the desired container and the first column would be the container ID.

Then to get the PID of that given container just run:

sudo docker inspect -f '' <container_id>

The filesystem will be in /proc/container_pid/root .

What is the use?

The main use I have for this is to use my preferred text editor to update running containers. This is very useful for live patching (nothing you should do in prod), since most of the times the container sizes are so reduce that there are no text editors installed.

With this little trick I save the time of installing an editor each time I want to do a live patch. Also, if you are a vim or emacs user you probably have it configured to your taste on the server.

Just remember that if the container is restarted, the changes are gone. Therefore you need some other way to restart the running services inside the container.