Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow on Docker: How to save the work on Jupyter notebook?

Newbie to both Docker and Tensorflow and trying them out. Installation (on win10, using hyper-v driver) went fine and I can run

docker run -p 8888:8888 -it gcr.io/tensorflow/tensorflow

and get output like this:

[I 23:01:01.188 NotebookApp]←(B Serving notebooks from local directory: /notebooks
[I 23:01:01.189 NotebookApp]←(B 0 active kernels
[I 23:01:01.189 NotebookApp]←(B The Jupyter Notebook is running at: http://[all ip addresses on your system]:8888/
[I 23:01:01.189 NotebookApp]←(B Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

and I can open Jupyter notebook from browser by opening [docker host address]:8888.

However, after doing some work (e.g., creating a new notebook), when I stop the server by Ctrl-C twice, all new work are lost. Maybe I'm missing something basic, so let me put what I'm not sure here:

  1. Am I supposed not to stop the server?
  2. I'm using the same "docker run" command when I restart. Is that correct?

Thanks for your help.

like image 285
ckcn Avatar asked Apr 20 '16 23:04

ckcn


2 Answers

You can mount current host folder to replace the default /notebooks folder in the container. Here is an example:

$ docker run -p 8888:8888 -v `pwd`:/notebooks -it gcr.io/tensorflow/tensorflow
[I 02:34:49.393 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[W 02:34:49.411 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 02:34:49.420 NotebookApp] Serving notebooks from local directory: /notebooks
[I 02:34:49.421 NotebookApp] 0 active kernels 
[I 02:34:49.421 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:8888/?token=b9da5de7f61d6a968dc07e55c6157606a4f2f378cd764a91
[I 02:34:49.421 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 02:34:49.422 NotebookApp] 

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=b9da5de7f61d6a968dc07e55c6157606a4f2f378cd764a91
like image 155
ontouchstart Avatar answered Nov 15 '22 23:11

ontouchstart


You want run the container as a daemon. Then you can docker stop and docker start the container and retrieve your work.

docker run -td -p 8888:8888 gcr.io/tensorflow/

Running with -it makes the container interactive and run in the foreground which is why the work is lost when you cancel it. Best practice and run it as a daemon so you don't have to CTRL+C to quit and can instead let docker handle the state.

like image 39
GHETTO.CHiLD Avatar answered Nov 16 '22 01:11

GHETTO.CHiLD