Docker jupyter笔记本使用容器ID作为ip,localhost

时间:2018-06-03 12:02:00

标签: python docker jupyter-notebook jupyter

我试图在基于python 3的Docker中运行jupyter笔记本。笔记本启动但显示容器ID为ip。如果我将其更改为“localhost:'在打开链接后在浏览器中。

如何使其正常工作并在网址中显示localhost: / os:Ubuntu 18.04 /

编辑:我已经尝试了jupyter/minimal-notebook并且有效,显示了本地主机,但它基于ubuntu 18.04,与我稍后想要在笔记本中使用的某些软件包不兼容。

Dockerfile:

FROM python:3
RUN apt-get -y update \
&& apt-get upgrade -y \
&& apt-get install -y \
    curl \
    vim \
    xterm
RUN pip install --upgrade pip
RUN pip install --no-cache-dir jupyter numpy matplotlib
# Add Tini. Tini operates as a process subreaper for jupyter. This prevents
# kernel crashes.
ENV TINI_VERSION v0.6.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini
RUN chmod +x /usr/bin/tini
ENTRYPOINT ["/usr/bin/tini", "--"]

EXPOSE 8888
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root"]

在构建

之后运行它
docker run --rm -it -p 8888:8888 -v "$PWD":/home/work e4b37115446d

输出:

[I 11:48:12.580 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[I 11:48:12.826 NotebookApp] Serving notebooks from local directory: /
[I 11:48:12.826 NotebookApp] 0 active kernels
[I 11:48:12.826 NotebookApp] The Jupyter Notebook is running at:
[I 11:48:12.826 NotebookApp] http://3b906c2d97f3:8888/?token=06d43a78966a7b7e5fd04318183fa3e7af5bca7542477d31
[I 11:48:12.826 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 11:48:12.827 NotebookApp] 

    Copy/paste this URL into your browser when you connect for the first time, to login with a token:
        http://3b906c2d97f3:8888/?token=06d43a78966a7b7e5fd04318183fa3e7af5bca7542477d31&token=06d43a78966a7b7e5fd04318183fa3e7af5bca7542477d31

1 个答案:

答案 0 :(得分:1)

运行容器时,请使用 --hostname 标志。如果将其保留为空,则默认为容器名称。

docker run --rm  -it -p 8888:8888 --hostname localhost jup

运行时:

[I 14:58:32.508 NotebookApp] The Jupyter Notebook is running at:
[I 14:58:32.508 NotebookApp] http://localhost:8888/?token=0e59cd9003b843f529b9bc6e7b39921001ddfdb253c029e9