Reputation: 2487
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
Upvotes: 1
Views: 1546
Reputation: 7813
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.
Upvotes: 2