【问题标题】:Docker jupyter notebook uses container id as ip, localhostDocker jupyter notebook 使用容器 id 作为 ip, localhost
【发布时间】:2018-11-12 22:31:45
【问题描述】:

我正在尝试基于 python 3 在 Docker 中运行 jupyter notebook。笔记本启动但将容器 ID 显示为 ip。如果我在打开链接后在浏览器中将其更改为“localhost:”,它确实有效。

如何使其正常工作并在 url 中显示 localhost:? /操作系统:Ubuntu 18.04/

编辑:我已经尝试过jupyter/minimal-notebook,它可以工作,显示 localhost,但它基于 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

【问题讨论】:

  • 我对 docker 没有太多经验,但是你应该跟进的错误不是明确的吗?你这样做了吗?
  • 谢谢,现在用我尝试过的方法编辑了问题

标签: python docker jupyter-notebook jupyter


【解决方案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

【讨论】:

    猜你喜欢
    • 2016-06-26
    • 1970-01-01
    • 2016-12-14
    • 1970-01-01
    • 2016-10-01
    • 2019-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多