0

If I launch a docker container with

docker run -v /foo:/foo ... 

I can see the contents of /foo on the host, from within the container.

While the docker container is running, if I run

mount -t ext4 /dev/... /foo/something 

I will NOT see the new mount point in /foo inside the container - is there any way to make it show up? (if I launch the docker container AFTER the mount point on the host is established, it is ok).

1 Answer 1

2

Docker containers run in a private mount namespace, which means that mounts made on the host after the container starts do not propagate into the container. The kernel documentation on shared subtrees goes into detail about mount propagation and private vs shared vs slave mounts.

The short answer to your question is that there isn't an easy way to expose a new mount like this into a container. It's possible, probably involving the use of nsenter to run commands inside the container namespace to change the flags on the mounts, but I wouldn't go there.

In general, if you need to change the storage configuration of a container, you re-deploy the container.

Sign up to request clarification or add additional context in comments.

2 Comments

yep - I had seen the inverse - with mounts inside the container being private - and I can certainly mount on the host with nsenter from within the container if I want... I was surprised that the mount was visible in the container after it was removed from the host. Fascinating stuff! thanks for the answer.
One legitimate case would be a USB/CD mount on the host being visible in docker - I am surprised I am unable to find similar questions along those lines.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.