简体   繁体   中英

Can't access jupyter notebook in docker (mac)

I want to install jupyter notebook into my docker image. After installation and running it in container, I can't access it from my browser.

Here is my minimal setup:

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:

    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..)

change you CMD line in the Dockerfile to CMD jupyter-lab notebook --ip 0.0.0.0 --port 8888 --allow-root

or edit jupyter_notebook_config.py within the container/image:
change line starting with c.NotebookApp.allow_origin to c.NotebookApp.allow_origin = '*'
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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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