Docker 错误:Jupyter Notebook 容器在成功构建后未运行

问题描述 投票:0回答:1

我有以下 Dockerfile:

# set the base image
FROM ubuntu:latest

# set python image
FROM python:3

# run update and setup functions
RUN apt-get update && apt-get -y upgrade
RUN apt-get install -y build-essential python-dev-is-python3
RUN apt-get install -y python-is-python3 2to3
RUN pip install pip --upgrade

# run jupyter install
RUN pip install jupyter

# set the working directory
WORKDIR /home/jupyter

# add python libraries
ADD requirements.txt /home/jupyter/

# make notebooks directory
RUN mkdir /home/jupyter/notebooks

# run the requirements.txt to pip install
RUN pip install -r requirements.txt

# run docker container with Jupyter Notebook
CMD ["jupyter", "notebook", "--allow-root", "--no-browser", "--ip 0.0.0.0", "--port 8888", "./notebooks"]

这个 Dockerfile 构建得很好,没有错误:

PS C:\<local_path>\Docker> docker build --tag notebook .
[+] Building 292.3s (15/15) FINISHED                                                               docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 805B                                                                               0.0s
 => [internal] load metadata for docker.io/library/python:3                                                        0.2s
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [stage-1  1/10] FROM docker.io/library/python:3@sha256:785fef11f44b7393c03d77032fd72e56af8b05442b051a15122914  0.0s
 => [internal] load build context                                                                                  0.0s
 => => transferring context: 38B                                                                                   0.0s
 => CACHED [stage-1  2/10] RUN apt-get update && apt-get -y upgrade                                                0.0s
 => CACHED [stage-1  3/10] RUN apt-get install -y build-essential python-dev-is-python3                            0.0s
 => CACHED [stage-1  4/10] RUN apt-get install -y python-is-python3 2to3                                           0.0s
 => CACHED [stage-1  5/10] RUN pip install pip --upgrade                                                           0.0s
 => CACHED [stage-1  6/10] RUN pip install jupyter                                                                 0.0s
 => CACHED [stage-1  7/10] WORKDIR /home/jupyter                                                                   0.0s
 => CACHED [stage-1  8/10] ADD requirements.txt /home/jupyter/                                                     0.0s
 => CACHED [stage-1  9/10] RUN mkdir /home/jupyter/notebooks                                                       0.0s
 => [stage-1 10/10] RUN pip install -r requirements.txt                                                          271.3s
 => exporting to image                                                                                            20.7s
 => => exporting layers                                                                                           20.7s
 => => writing image sha256:3a4066929f1f16f0d66749dd13155526c280170e29284032bd6a64bd12f87267                       0.0s
 => => naming to docker.io/library/notebook                                                                        0.0s

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/h8u0s757guiu9enx1xqsjvj7k

What's next:
    View a summary of image vulnerabilities and recommendations → docker scout quickview

然后我运行以下命令

docker run -p 8888:8888 -v C:/<local_path>:/home/jupyter/notebooks notebook
并收到以下错误:
[C 2024-10-04 02:09:02.474 ServerApp] No such file or directory: /home/jupyter/--ip 0.0.0.0

我的 Dockerfile 中是否缺少某些内容?任何帮助都是值得赞赏的,因为我觉得这是我所缺少的简单的东西。

我尝试添加

EXPOSE 8888
,但仍然收到相同的错误。我还尝试使用
pipx
但一开始就无法构建图像。我恢复到几周前在更新到 Docker v4.34.2 之前运行的 Dockerfile(上图)。

docker dockerfile
1个回答
0
投票

Dockerfile

  • /home/jupyter
    更改为
    /jupyter

/home/jupyter
用于用户
jupyter
的主目录。 但你通过
root
运行应用程序,然后我将目录更改为
/jupyter

  • /home/jupyter/notebooks
    更改为
    /jupyter/notebook

notebooks
notebook

  • 添加
    runit.sh
  • 改变
    CMD
# set the base image
FROM ubuntu:latest

# set python image
FROM python:3

# run update and setup functions
RUN apt-get update && apt-get -y upgrade
RUN apt-get install -y build-essential python-dev-is-python3
RUN apt-get install -y python-is-python3 2to3
RUN pip install pip --upgrade

# run jupyter install
RUN pip install jupyter

# set the working directory
# WORKDIR /home/jupyter

WORKDIR /jupyter

# add python libraries
# ADD requirements.txt /home/jupyter/

ADD requirements.txt /jupyter/

ADD runit.sh ./
RUN chmod +x runit.sh


# make notebooks directory
# RUN mkdir /home/jupyter/notebooks

RUN mkdir -p /jupyter/notebook

# run the requirements.txt to pip install
RUN pip install -r requirements.txt

# run docker container with Jupyter Notebook
# CMD ["jupyter", "notebook", "--allow-root", "--no-browser", "--ip 0.0.0.0", "--port 8888", "./notebooks"]


CMD ["bash", "runit.sh"]

runit.sh

# jupyter notebook --allow-root --no-browser --ip 0.0.0.0 --port 8888 ./notebooks

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

构建

docker build --tag notebook .

奔跑

  • /jupyter/notebooks
    更改为
    /jupyter/notebook
docker run -it -p 8888:8888 -v C:/<local_path>:/jupyter/notebook notebook
© www.soinside.com 2019 - 2024. All rights reserved.