簡體   English   中英

無法訪問 docker 容器內的 jupyter 筆記本

[英]Can't access jupyter notebook inside docker container

我知道有很多人正在為此苦苦掙扎,但請閱讀整篇文章。
所以我只想創建一個 dockerfile 公開端口 8888 以便稍后訪問 jupyter 筆記本。

這是我的 dockerfile:

FROM continuumio/anaconda3
ENV DEBIAN_FRONTEND=noninteractive

ARG USERNAME=remote
ARG USER_UID=1000
ARG USER_GID=$USER_UID

COPY environment.yml* noop.txt /tmp/conda-tmp/

RUN apt-get update \
    && apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
    && apt-get -y install git openssh-client less iproute2 procps iproute2 lsb-release \
    && if [ -f "/tmp/conda-tmp/environment.yml" ]; then /opt/conda/bin/conda env update -n base -f /tmp/conda-tmp/environment.yml; else echo "did not find environment.yml"; fi \
    && rm -rf /tmp/conda-tmp \
    && groupadd --gid $USER_GID $USERNAME \
    && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
    && apt-get install -y sudo \
    && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
    && chmod 0440 /etc/sudoers.d/$USERNAME \
    && apt-get autoremove -y \
    && apt-get clean -y \
    && rm -rf /var/lib/apt/lists/*

ENV DEBIAN_FRONTEND=dialog

EXPOSE 8888

我運行以下命令來啟動並運行容器:

docker build -t intel . (create the image)
docker run -t -d --publish=8888:8888 --name ig intel (start a container based on the image)

到目前為止,一切運行都沒有任何問題,但現在出現了我不明白的事情:
這運行得很好。 jupyter notebook --allow-root --no-browser --ip 0.0.0.0 --port 8888

但是當我嘗試 go 到

localhost:8888?/token=(the token jupyter provides)
or
ipofthecontainer:8888?/token=(the token jupyter provides)

它什么都不做(連接超時),我不知道為什么。

我檢查了容器的 ip:

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name

我驗證 EXPOSE 是否與:

碼頭工人ps

平台:windows
蟒蛇版本:3.7.7
conda 環境:是的

我在這里沒有看到什么?

EXPOSE僅用於文檔; 它沒有效果。

您需要將--publish=8888:8888添加到您的docker run中,以便將容器的端口映射到主機端口。

docker run --tty --detach --publish=8888:8888 --name=ig intelligait3d

注意publish標志不需要host-port:container-port匹配

首先修改您的 docker 文件以啟動 jupyter notebook,在 Dockerfile 的末尾添加此行:

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

然后再次構建映像,並在啟動容器時使用-p選項:-- --publish, -p Publish a container's port(s) to the host

docker run -t -d -p 8888:8888 --name ig intelligait3d其中映射為-p <HOST port>:<CONTAINER port>

在這里您可以找到docker run命令的參考: https://docs.docker.com/engine/reference/commandline/run/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM