6

I run Jupyter Notebook with Docker and trying to mount local directory onto the intended Docker volume. But I am unable to see my files in the Jupyter notebook. The Docker command is

sudo nvidia-docker create -v ~/tf/src -it -p 8888:8888 
   -e PASSWORD=password 
   --name container_name gcr.io/tensorflow/tensorflow:latest-gpu

and the GUI of the Jupyter Notebook looks like

Jupyter notebook

but ~/tf/src are not shown up in the Jupyter GUI.

What are needed for the files to shown up in the Jupyter? Am I initializing the container incorrectly for this?

hhh
  • 50,788
  • 62
  • 179
  • 282
Karl L
  • 260
  • 4
  • 9

4 Answers4

6

the way you mount your volume i think its incorrect -v ~/tf/src it should be

-v /host/directory:/container/directory

Fendi jatmiko
  • 2,567
  • 1
  • 9
  • 15
  • There is one missing piece, sudo nvidia-docker create -v /Users/user/tf/src:/notebooks -it -p 8888:8888 -e PASSWORD=password --name container_name gcr.io/tensorflow/tensorflow:latest-gpu "/notebooks" is the directory jupyter puts its files – Karl L Jan 08 '18 at 19:48
  • 1
    On latest version I'm seeing the notebooks in `/tf` rather than `/notebooks` so ... `docker run --runtime=nvidia -it --name tensorflow -p 8888:8888 -v ~/:/tf/ tensorflow/tensorflow:nightly-jupyter` with an appropriate `` and ``. – Ian Mercer Oct 04 '20 at 18:30
2

Ferdi D's answer targets only files inside interpreter, not precisely files inside Jupyter GUI, which makes things a little bit confusing. I target the title Show volume files in docker jupyter notebook by more generally showing the filse inside Jupyter notebook.


Files inside the interpreters

The -v flag gets you the files in the interpreter or the notebook but not necessarily in the Jupyter GUI

enter image description here

for which you run

$ docker run --rm -it -p 6780:8888 -v "$PWD":/home/jovyan/ jupyter/r-notebook

because the mount point depends on a distribution and hence its path. Here, you ask your current directory to be mounted to Jupyter's path /home/jovyan.

Files inside Jupyter GUIs

To get the files in Jupyter GUI:

OS X

If you had some other than /home/jovyan at the current Jupyter version, the files would not appear in Jupyter GUI so use

$ docker run --rm -it -p 6780:8888 -v "$PWD":/home/jovyan/ jupyter/r-notebook

Some other distros

$ docker run --rm -it -p 6780:8888 -v "$PWD":/tmp jupyter/r-notebook

More generally

For checking up for /home/jovyan/ or /tmp, you can getwd() in R to see your working directory.

enter image description here

Further threads

  1. Reddit discussion more generally on the topic here
hhh
  • 50,788
  • 62
  • 179
  • 282
2

Posting this as an answer since the location seems to have changed and the accepted answer doesn't spell it out in full how to get your local directory to show up in Tensorflow Jupyter (Type this on one line with an appropriate <localdir> and <dockerdir>):

 docker run --runtime=nvidia -it 
            --name tensorflow 
            -p 8888:8888 
            -v ~/<localdir>:/tf/<dockerdir> 
            tensorflow/tensorflow:nightly-jupyter 
Ian Mercer
  • 38,490
  • 8
  • 97
  • 133
0

Karl L thinks the solution is the following below. The solution moved here for everyone to judge it and make the question easier to read.


Solution

sudo nvidia-docker create -v /Users/user/tf/src:/notebooks 
   -it -p 8888:8888 -e PASSWORD=password 
   --name container_name gcr.io/tensorflow/tensorflow:latest-gpu

As @fendi-d pointed out I was mounting my volume incorrectly.

Then I was pointed to the incorrect mounting dir and I found the correct one in the tensorflow docker file https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/dockerfiles/dockerfiles/gpu.Dockerfile

Which configures the jupyter notebook and then copies files to "/notebooks"

# Set up our notebook config.
COPY jupyter_notebook_config.py /root/.jupyter/

# Copy sample notebooks.
COPY notebooks /notebooks

After I ran with the correct mounting path it showed my files located in "/Users/user/tf/src"

Ian Mercer
  • 38,490
  • 8
  • 97
  • 133
hhh
  • 50,788
  • 62
  • 179
  • 282