Mounted Docker volume has different ownership when using Travis

Viewed 375

This question relates to this repository with the most relevant Travis job here.

The repository is for static site built from Jupyter notebooks. The notebooks are converted using build/build.py which, for each post, builds a Docker image, starts a corresponding container with the post notebook directory mounted, and uses nbconvert to convert the notebook to Markdown. One step of nbconvert's conversion involves creating a supporting file directory. This fails on Travis due to a permission issue.

In attempting to debug this problem, I found that the ownership and permissions of the repo are the same on my local machine and Travis (with my username switched for travis) before running Docker. Despite this, inside the mounted volume of the Docker container, the ownerships are different:

Local:

drwxrwxr-x 3 jovyan  1000   4096 Dec 10 19:56 .
drwsrwsr-x 1 jovyan users   4096 Dec  3 21:51 ..
-rw-rw-r-- 1 jovyan  1000    105 Dec  7 09:57 Dockerfile
drwxr-xr-x 2 jovyan  1000   4096 Dec 10 12:09 .ipynb_checkpoints
-rw-r--r-- 1 jovyan  1000 154229 Dec 10 12:28 post.ipynb

Travis:

drwxrwxr-x 2   2000  2000  4096 Dec 10 19:58 .
drwsrwsr-x 1 jovyan users  4096 Nov  8 16:37 ..
-rw-rw-r-- 1   2000  2000   101 Dec 10 19:58 Dockerfile
-rw-rw-r-- 1   2000  2000 35271 Dec 10 19:58 post.ipynb

Both my local machine and Travis are running Ubuntu 20.04, have the same version of Docker, and all other tools come from Conda so should behave the same. I am struggling to understand where this difference in ownership is coming from.

1 Answers

Try running the docker again with this command, so the uid outside the container is propagated inside:

docker run -u `id -u`

alternative, as pointed by @anemyte:

docker run -u $(id -u)

This should involve the creation of the new files inside the docker to be owned by "jovyan".

If you are able to guess that mounting points will exist, you could also pre-create them so the ownership of the files inside is also correct:

docker run -v /path/on/host:/path/in/container ...

If you set the permissions of your local path (/path/on/host) as 777, that will also be propagated to the mounting point: no permission error will be thrown regardless of the user that docker uses to create those files.

After that, you'll be free to restore permissions, if needed.

Related