简体   繁体   English

Docker上的Tensorflow:如何在Jupyter笔记本上保存工作?

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

Newbie to both Docker and Tensorflow and trying them out. Docker和Tensorflow的新手并试用它们。 Installation (on win10, using hyper-v driver) went fine and I can run 安装(在win10上,使用hyper-v驱动程序)运行良好,我可以运行

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. 我可以通过打开[docker host address]:8888从浏览器打开Jupyter笔记本。

However, after doing some work (eg, creating a new notebook), when I stop the server by Ctrl-C twice, all new work are lost. 但是,在完成一些工作(例如,创建新笔记本)后,当我通过Ctrl-C两次停止服务器时,所有新工作都将丢失。 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. 我重新启动时使用相同的“docker run”命令。 Is that correct? 那是对的吗?

Thanks for your help. 谢谢你的帮助。

You want run the container as a daemon. 您希望将容器作为守护程序运行。 Then you can docker stop and docker start the container and retrieve your work. 然后你可以使用docker stopdocker start容器并检索你的工作。

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. 使用-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. 最佳实践并将其作为守护程序运行,因此您不必使用CTRL + C退出,而是可以让docker处理该状态。

You can mount current host folder to replace the default /notebooks folder in the container. 您可以挂载当前主机文件夹以替换容器中的默认/notebooks文件夹。 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

I run Docker as a named container: 我将Docker作为命名容器运行:

$ docker run -p 8888:8888 -d --name appu b.gcr.io/tensorflow-udacity/assignments

appu is the name I have given to my container. appu是我给容器的名字。

-p forwards port number 8888 from Linux to Windows. -p将端口号8888从Linux转发到Windows。

-d makes the program run in the background, so that you get the $ prompt on your console and can continue to work with other tasks (this is what is called 'demonizing', but don't be intimidated by geeks. It just means 'please run silently in the background, and give me back my console' !) When you want to stop the container, mention it by name -d使程序在后台运行,这样你就可以在控制台上获得$ prompt并继续使用其他任务(这就是所谓的'妖魔化',但不要被极客吓倒。这只是意味着'请在后台默默运行,然后把我的控制台给我!)当你想要停止容器时,请按名称提及

$ docker stop appu

Next time you want to get the same container back, with all the files you created in your earlier session, start the container appu again: 下次要使用在先前会话中创建的所有文件返回同一容器时,再次启动容器appu:

$ docker start appu

First time, run Docker as a named container in interactive mode. 第一次,在交互模式下将Docker作为命名容器运行。 This would give you the link with token. 这将为您提供与令牌的链接。 For the subsequent runs, start the container with name. 对于后续运行,请使用名称启动容器。 Here is an example: 这是一个例子:

First run: 第一次运行:

$ docker run -p 8888:8888 -d --name <name> gcr.io/tensorflow/tensorflow

When required stop the first run with ctrl-C. 需要时,使用ctrl-C停止第一次运行。

Subsequent runs: 后续运行:

$ docker start <name>

This would automatically run the docker in background mode. 这将在后台模式下自动运行docker。

To stop the container: 要停止容器:

$ docker stop <name>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用官方Tensorflow docker容器在主机目录中保存和编辑Jupyter笔记本? - How to save and edit a Jupyter notebook in a host directory using official Tensorflow docker container? 我如何启动 tensorflow docker jupyter notebook - How do I start tensorflow docker jupyter notebook 运行tensorflow docker时如何更改jupyter笔记本端口? - How to change jupyter notebook port when running tensorflow docker? docker 如何处理 jupyter notebook 的权限 - 3 种不起作用的方法 - docker how to handle permissions for jupyter notebook - 3 approaches that do not work 如何在 Tensorflow + Jupyter Notebook + GPU 中使用 docker-compose.yml - How do I use docker-compose.yml with Tensorflow + Jupyter Notebook + GPU 无法更改在 tensorflow docker 容器上运行的 jupyter 笔记本的工作目录 - Unable to change working directory for a jupyter notebook running on a tensorflow docker container 尝试使用 Docker jupyter/tensorflow-notebook 登录 Jupyter notebook 时令牌无效 - Invalid token when trying to login into Jupyter notebook with Docker jupyter/tensorflow-notebook 如何从服务器上的Docker访问Jupyter Notebook? - How to access jupyter notebook from docker on server? 如何使用 docker 和 ubuntu 运行 jupyter notebook? - How to run jupyter notebook using docker with ubuntu? 如何在 docker 的特定文件夹中运行 jupyter notebook - How to run a jupyter notebook at a particular folder in docker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM