1

For development, testing and analysis purposes I would like to be able to manage the container's file-system directly on the host.

Using this simple hack...

cd /proc/$(docker inspect --format {{.State.Pid}} <YOUR_CONTAINER_ID>)/root

... I can manage the container's file-system files in a simple way. However, I can only do it as root.

I'm not an expert in Docker, so I'd like to get some feedback from the community. Any recommendations? Is there a better way to do this?

IMPORTANT: I know that manage the container's data in its own file-system is not seen as a good practice, much less persist that data directly into its file-system. I just want to make my development, testing and analysis process more agile and simple. This process will not be adopted in the production environment.

PLUS: I would like to manage the container's file-system as regular user and not as root. Is it possible to do this using the presented method? This way I could use file managers like Dolphin, Nautilus, Thunar, etc.

THANKS!

REFERENCE:
https://stackoverflow.com/a/32498954/3223785
https://superuser.com/a/1288058/195840
https://github.com/moby/moby/issues/26872

Eduardo Lucio
  • 1,771
  • 2
  • 25
  • 43
  • 1
    Can bind-mount meet your needs? – Yuankun Mar 28 '18 at 02:37
  • @Yuankun How would you do it? Would changes be reflected in the container's file-system? Please put your approach (answer) here. If it meets my needs I will mark it as an accepted response! Thank you! =D – Eduardo Lucio Mar 29 '18 at 18:41

1 Answers1

2

Accessing container's filesystem is highly discouraged. If what you need is to share files between host and container, bind-mount is your option.

See, if I have a code directory /home/yuankun/code. I want to share this directory to the running container, so that any changes made to this directory will be immediately visible to the container. This is the command to start the container:

docker run -v /home/yuankun/code:/code <IMAGE>

Where the -v option tells the Docker Engine to bind-mount the /home/yuankun/code directory to the container. You can access your codes in the /code directory inside the container.

Yuankun
  • 6,875
  • 3
  • 32
  • 34