I am new to Docker and I want to use it to get a controlled compilation environment for my code.
I already have a Docker image with all the tools I need. My problem at the moment is as follows:
- I have my code in the host machine, inside my home folder that is mounted from an NFS server
- I want to make this folder visible inside the Docker container with r+w permissions
Here's what I tried first (running the container with the source folder as a volume) and the error I get:
[mbrandalero@machine ~]$ docker run -it --cap-add sys_admin -v "/homes/mbrandalero/src:/usr/local/src/" mbrandalero/my-image bash /usr/bin/docker-current: Error response from daemon: error while creating mount source path '/homes/mbrandalero/src': mkdir /homes/mbrandalero/src: permission denied.
(apparently it is trying to create the directory on the host side, but it is already there)
Curiously enough, when I try running the container with the whole home folder as a volume, it works but yields a different error (no write permission in the folder):
[mbrandalero@machine ~]$ docker run -it --cap-add sys_admin -v "/homes/mbrandalero/:/usr/local/src/home" mbrandalero/my_image bash root@46712ad936f2:/usr/local/src# cd home/ bash: cd: home/: Permission denied root@46712ad936f2:/usr/local/src# ls -lah | grep "\(\.\|home\)" total 4.0K drwxr-xr-x 1 root root 18 May 20 14:50 . drwxr-xr-x 1 root root 17 May 15 14:06 .. drwxr-x--- 30 10031 10031 4.0K May 20 15:03 home
Am I doing it right? What am I missing?
- OS: CentOS Linux 7.6
- Docker version: 1.13.1
Apparently setting a user id when running
docker run fixes the issue, but is this the right way of doing it? Running it this way sort of fixed things, but looks odd (I get "I have no name!" as username):
[mbrandalero@machine ~]$ docker run -it --cap-add sys_admin -v "/homes/mbrandalero/:/usr/local/src/home" --user $(id -u) mbrandalero/my_image bash I have no name!@2efec822e572:/usr/local/src$ cd home/ I have no name!@2efec822e572:/usr/local/src/home$