简体   繁体   English

无法在 docker(mac)中访问 jupyter 笔记本

[英]Can't access jupyter notebook in docker (mac)

I want to install jupyter notebook into my docker image.我想将 jupyter notebook 安装到我的 docker 映像中。 After installation and running it in container, I can't access it from my browser.在容器中安装并运行后,我无法从浏览器访问它。

Here is my minimal setup:这是我的最小设置:

Dockerfile: Dockerfile:

FROM python:3.7.5
RUN pip install jupyterlab
EXPOSE 8888
CMD jupyter-lab --allow-root

commands命令

docker build -t my_image .
docker run -p 8888:8888 my_image

container output:集装箱 output:

    To access the server, open this file in a browser:
        file:///root/.local/share/jupyter/runtime/jpserver-7-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/lab?token=e6b9a5dd573aabc52e6753e7b21f0daf6270e685055afa50
     or http://127.0.0.1:8888/lab?token=e6b9a5dd573aabc52e6753e7b21f0daf6270e685055afa50

I try to open any of these links, and get this message in browser:我尝试打开这些链接中的任何一个,并在浏览器中收到此消息:

This page isn’t working
localhost didn’t send any data.
ERR_EMPTY_RESPONSE

What am I doing wrong?我究竟做错了什么?

By default Jupyter is configured to listen only on localhost interface, you need to config it to listen on 0.0.0.0 (the container's localhost isn't your host localhost..)默认情况下,Jupyter 配置为仅侦听 localhost 接口,您需要将其配置为侦听 0.0.0.0(容器的 localhost 不是您的主机 localhost..)

change you CMD line in the Dockerfile to CMD jupyter-lab notebook --ip 0.0.0.0 --port 8888 --allow-root将 Dockerfile 中的CMD行更改为CMD jupyter-lab notebook --ip 0.0.0.0 --port 8888 --allow-root

or edit jupyter_notebook_config.py within the container/image:或在容器/图像中编辑jupyter_notebook_config.py
change line starting with c.NotebookApp.allow_origin to c.NotebookApp.allow_origin = '*'将从c.NotebookApp.allow_origin开始的行更改为c.NotebookApp.allow_origin = '*'
and change line starting with c.NotebookApp.ip to c.NotebookApp.ip = '0.0.0.0' and change line starting with c.NotebookApp.ip to c.NotebookApp.ip = '0.0.0.0'

used this question for help: Why I can't access remote Jupyter Notebook server?使用此问题寻求帮助: 为什么我无法访问远程 Jupyter Notebook 服务器?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM