0

I want to give a docker container to my students such that they are able to conduct experiments. I thought I use the following dockerfile:

FROM jupyter/datascience-notebook:latest

ADD ./config.json /home/jovyan/.jupyter/jupyter_notebook_config.json
ADD ./books /home/jovyan/work

So, the standard container will include a few notebooks I have created and stored in the books folder. I then build and run this container locally with

#!/usr/bin/env bash
docker build -t aaa .
docker run --rm -p "8888:8888" -v $(pwd)/books:/home/joyvan/work aaa

I build the container aaa and share again the folder books with it (although books has been copied into the image at compile time). I now open the container on port 8888. I can edit the files in the /home/joyvan/work folder but this stuff is not getting transported back to the host. Something goes terrible wrong. Is it because I add the files during the docker build and then share them again in the -v ...?

I have played with various options. I have added the local user to the users group. I do chown on all files in books. All my files show up as root:root in the container. I am then joyvan in the container and do not have write access to those files. How would I make sure the files are owned by joyvan?

EDIT:

Some other elements :

tom@thomas-ThinkPad-T450s:~/babynames$ docker exec -it cranky_poincare /bin/bash
jovyan@5607ac2bcaae:~$ id
jovyan uid=1000(jovyan) gid=100(users) groups=100(users)
jovyan@5607ac2bcaae:~$ cd work/
jovyan@5607ac2bcaae:~/work$ ls
test.txt text2.txt
jovyan@5607ac2bcaae:~/work$ ls -ltr
total 4
-rw-rw-r-- 1 root root 5 Dec 12 19:05 test.txt
-rw-rw-r-- 1 root root 0 Dec 12 19:22 text2.txt

on the host:

tom@thomas-ThinkPad-T450s:~/babynames/books$ ls -ltr
total 4
-rw-rw-r-- 1 tom users 5 Dez 12 20:05 test.txt
-rw-rw-r-- 1 tom users 0 Dez 12 20:22 text2.txt
tom@thomas-ThinkPad-T450s:~/babynames/books$ id tom
uid=1001(tom) gid=1001(tom) groups=1001(tom),27(sudo),100(users),129(docker)
vmonteco
  • 14,136
  • 15
  • 55
  • 86
tschm
  • 2,905
  • 6
  • 33
  • 45
  • 1
    Are the relevant files present when you manually check with a shell session? Did you have any traceback/logs when building? – vmonteco Dec 12 '17 at 20:05
  • Yes the files make it into the container, I have checked with docker exec -it some_container_name /bin/bash. but they are all root:root – tschm Dec 12 '17 at 20:19
  • 1
    What user runs your service in your container? What are his UID/GID? Also, do you have any error message/traceback and do the changes appear in your container when you edit? – vmonteco Dec 12 '17 at 20:24
  • 1
    Could you also run `ls -l books`? – vmonteco Dec 12 '17 at 20:26
  • when I edit the files within Jupyter and try to store/update them I get permission denied... (note that they are rw rw r for root:root) – tschm Dec 12 '17 at 20:37
  • 1
    I added your output to your post, you may delete your comment. But could you also add the output for `~/work` itself and for your mounpoint from the host point of view? – vmonteco Dec 12 '17 at 20:37
  • Don't you have the ls output for the `work` directory itself as well? – vmonteco Dec 12 '17 at 20:45
  • Not sure I understand your question. Note that there is also plenty of documentation on dockerhub for my base-image. But unfortunately it's not the most accessible piece of doc – tschm Dec 12 '17 at 20:48
  • 1
    Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/161062/discussion-between-vmonteco-and-tschm). – vmonteco Dec 12 '17 at 20:53

1 Answers1

0

You can try:

FROM jupyter/datascience-notebook:latest

ADD ./config.json /home/jovyan/.jupyter/jupyter_notebook_config.json
ADD ./books /home/jovyan/work
RUN chown joyvan /books

if that user already exists, but with RUN you can execute all commands in your docker file.

Michael Ploeckinger
  • 1,616
  • 1
  • 11
  • 24
  • I don't think so, but I try... see also https://stackoverflow.com/questions/26145351/why-doesnt-chown-work-in-dockerfile – tschm Dec 12 '17 at 20:14