如何在docker容器中打开jupyter nookbooks?

时间:2017-04-22 23:09:01

标签: python docker docker-compose jupyter-notebook jupyter

运行docker-compose ps时,我有以下容器:

 Name                    Command             State           Ports          
---------------------------------------------------------------------------------
rainmaker_db_1       docker-entrypoint.sh mysqld   Up      0.0.0.0:3306->3306/tcp 
rainmaker_python_1   python -u /app/run.py         Up      0.0.0.0:5000->5000/tcp

我想在容器rainmaker_python_1中运行jupyther,所以我运行以下命令:

docker-compose exec python jupyter notebook --allow-root

然后我得到以下输出:

[I 23:03:19.168 NotebookApp] Serving notebooks from local directory: /app
[I 23:03:19.168 NotebookApp] 0 active kernels 
[I 23:03:19.168 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/?token=35ff0fa9ec171204dbd7542d9c493c760055de24e1b7af18
[I 23:03:19.168 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 23:03:19.169 NotebookApp] No web browser found: could not locate runnable browser.
[C 23:03:19.169 NotebookApp] 

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=35ff0fa9ec171204dbd7542d9c493c760055de24e1b7af18

但是,如果我复制并粘贴链接http://localhost:8888/?token=35ff0fa9ec171204dbd7542d9c493c760055de24e1b7af18,我就会发现该网站无法访问。然后我试了一下:

http://localhost:5000/?token=35ff0fa9ec171204dbd7542d9c493c760055de24e1b7af18

但我得到以下内容:

enter image description here

我想能够执行jupyter笔记本,所以我希望有人可以帮助我。我几乎没有使用Docker的经验。

1 个答案:

答案 0 :(得分:2)

看起来Jupyter笔记本的默认端口号是8888.当您的Docker容器启动Jupyter时,您可以在控制台输出中看到这一点。

更改Docker撰写文件中的端口映射,就像我在下面所做的那样,或者查看是否有一个环境变量可以在Docker compose文件中设置,以使Docker / Jupyter在你拥有的端口上运行打开(5000)。

下面,Docker compose部分在端口8888上设置节点服务器(感谢copypasta),但应提供足够的示例来更改你的) - 真正唯一重要的一行是端口线。

version: '2'
services:
  nodejs:
    build:
      context: .
       dockerfile: DockerFile
     ports:
       - "8888:8888"