简体   繁体   English

使用jupyter笔记本运行docker图像的问题

[英]problem running docker image using jupyter notebook

I have a jupyter notebook and a data file in a folder. 我有一个jupyter笔记本和一个文件夹中的数据文件。 I made a Dockerfile and wrote the following lines 我制作了一个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"]

I can successfully build an image using docker build -t nameofimage But when I do docker run -it nameofimage . 我可以使用docker build -t nameofimage成功构建一个图像但是当我做docker run -it nameofimage I get an error [FATAL tini (7)] exec jupyter notebook failed: No such file or directory . 我收到错误[FATAL tini (7)] exec jupyter notebook failed: No such file or directory

How do I run this jupyter notebook in docker? 如何在docker中运行这个jupyter笔记本?

EDIT: 编辑:

I tried two replacements on the last line, 我在最后一行尝试了两次更换,
I replaced the last line with 我替换了最后一行

# Start the jupyter notebook
ENTRYPOINT ["jupyter", "notebook", "--ip=*"]

It runs and gives a token on the screen but when I paste the token on localhost, It gives invalid credentials error 它在屏幕上运行并提供令牌,但是当我将令牌粘贴到localhost上时,它会提供无效的凭据错误

then I replaced the last line with 然后我用最后一行替换了

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

It runs and gives a token on the screen but when I paste the token on localhost, It gives invalid credentials error 它在屏幕上运行并提供令牌,但是当我将令牌粘贴到localhost上时,它会提供无效的凭据错误

If you check the original Dockerfile , you will find the following; 如果您检查原始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 will get you a valid token. start-notebook.sh将为您提供有效的令牌。 Subsequent files allow to interact with the image, these options are described in the docs . 后续文件允许与图像交互,这些选项在文档中描述。

Mind that there are more caveats, eg which user is running commands described in Dockerfile: root or jovyan (Jupyter user)? 请注意还有更多的警告,例如哪个用户正在运行Dockerfile中描述的命令: rootjovyan (Jupyter用户)? Commands executed by root may set permissions in a way that won't allow jovyan to eg load given package. root执行的命令可以以不允许jovyan例如加载给定包的方式设置权限。 To fix this, there's an extra line in all Jupyter (base notebook and derived) Dockerfiles: 要解决这个问题,所有Jupyter(基本笔记本和派生)Dockerfiles中都有一个额外的行:

RUN fix-permissions /etc/jupyter/

Here is an example how a derived notebook could look like. 以下是派生笔记本的外观示例。

In essence, either remove your custom ENTRYPOINT / CMD and use the original ones or make sure you eg get the token right. 实质上,要么删除您的自定义ENTRYPOINT / CMD并使用原始的ENTRYPOINT / CMD,请确保您获得正确的令牌。 Also, fix permissions. 另外,修复权限。

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

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