使用jupyter笔记本运行docker映像时出现问题

时间:2019-04-28 20:07:41

标签: python docker jupyter-notebook

我在文件夹中有一个jupyter笔记本和一个数据文件。我制作了一个Dockerfile并写了以下几行

FROM jupyter/base-notebook

ARG export_file=FooD_Kind.csv

RUN pip install jupyter

RUN pip install numpy

RUN pip install matplotlib

RUN pip install pandas

RUN pip install pulp

COPY $export_file FooD_Kind.csv

COPY task_4kind.ipynb /

CMD ["jupyter notebook", "task_4kind.ipynb"]

我可以使用docker build -t nameofimage成功构建映像,但是当我执行docker run -it nameofimage时。我收到错误[FATAL tini (7)] exec jupyter notebook failed: No such file or directory

如何在docker中运行此jupyter笔记本?

编辑:

我在最后一行尝试了两次替换,
我用

替换了最后一行
# Start the jupyter notebook
ENTRYPOINT ["jupyter", "notebook", "--ip=*"]

它运行并在屏幕上给出一个令牌,但是当我将该令牌粘贴到localhost时,它给出了无效的凭证错误

然后我将最后一行替换为

CMD jupyter notebook --port=8888 --no-browser --ip=0.0.0.0 --allow-root

它运行并在屏幕上给出一个令牌,但是当我将该令牌粘贴到localhost时,它给出了无效的凭证错误

1 个答案:

答案 0 :(得分:2)

如果选中original Dockerfile,则会发现以下内容;

ENTRYPOINT ["tini", "-g", "--"]
CMD ["start-notebook.sh"]

# Add local files as late as possible to avoid cache busting
COPY start.sh /usr/local/bin/
COPY start-notebook.sh /usr/local/bin/
COPY start-singleuser.sh /usr/local/bin/

start-notebook.sh将为您提供有效的令牌。后续文件允许与图像进行交互,这些选项在docs中进行了描述。

请注意,还有更多警告,例如哪个用户正在运行Dockerfile中描述的命令:rootjovyan(Jupyter用户)?由root执行的命令可能会以不允许jovyan的方式设置权限,例如加载给定的包。要解决此问题,所有Jupyter(基础笔记本和派生的)Dockerfile中都有一行额外的内容:

RUN fix-permissions /etc/jupyter/

Here是一个派生笔记本的外观示例。

从本质上讲,要么删除您自定义的ENTRYPOINT / CMD并使用原始的,要么确保您例如正确获得令牌。另外,修复权限。