Docker mount a volume as root

2019-05-29 02:33发布

问题:

The problem description

I have a Docker image, which is being executed with volume mounting options a large number of times. It is built in a way so that the default user does not have root permissions. However I need to make sure that when I mount the volume it is being mounted as root and not as the current working user because of security concerns. (The current working non-root user must not be allowed to delete any files inside the mounted volume.)

Example

From the host machine:

docker run -it -v /path/to/mount:/container/mounting/path image-name

Inside the container current-user@docker-container:

All of the files inside /container/mounting/path must have owner permissions root root and not current-user current-user.