【发布时间】:2020-01-31 22:17:26
【问题描述】:
Docker 对我来说相当新,我正在创建一个类似的 jupyterhub 容器
FROM ubuntu:18.04
LABEL maintainer="Jupyter Project <jupyter@googlegroups.com>"
# install nodejs, utf8 locale, set CDN because default httpredir is unreliable
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -y update && \
apt-get -y upgrade && \
apt-get -y install wget git bzip2 && \
apt-get purge && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
ENV LANG C.UTF-8
# install Python + NodeJS with conda
RUN wget -q https://repo.continuum.io/miniconda/Miniconda3-4.5.11-Linux-x86_64.sh -O /tmp/miniconda.sh && \
echo 'e1045ee415162f944b6aebfe560b8fee */tmp/miniconda.sh' | md5sum -c - && \
bash /tmp/miniconda.sh -f -b -p /opt/conda && \
/opt/conda/bin/conda install --yes -c conda-forge \
python=3.6 sqlalchemy tornado jinja2 traitlets requests pip pycurl \
nodejs configurable-http-proxy && \
/opt/conda/bin/pip install --upgrade pip && \
rm /tmp/miniconda.sh
ENV PATH=/opt/conda/bin:$PATH
ADD . /src/jupyterhub
WORKDIR /src/jupyterhub
RUN npm install -g configurable-http-proxy
RUN python3 -m pip install jupyterhub
RUN python3 -m pip install dockerspawner
WORKDIR /srv/jupyterhub/
EXPOSE 8000
COPY jupyterhub_config.py /srv/jupyterhub/jupyterhub_config.py
LABEL org.jupyter.service="jupyterhub"
CMD ["jupyterhub"]
使用以下配置文件,基于this discussion
# launch with docker
c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner'
# we need the hub to listen on all ips when it is in a container
c.JupyterHub.hub_ip = '0.0.0.0'
c.JupyterHub.port = 8000
c.DockerSpawner.extra_host_config = {'network_mode': 'host'}
c.DockerSpawner.use_internal_ip = True
c.DockerSpawner.network_name = 'host'
然后我做:
docker run -i -p 8000:8000 --name jupyterhub jupyterhub:latest jupyterhub -f jupyterhub_config.py
它在我的内部网络上按预期工作,但我无法在外部访问它。如果我这样做:
my_ip:8000
我无法连接。
对于我在 docker 上运行的 Flask 应用程序,我所做的只是在 0.0.0.0 ip 中运行该应用程序并且它可以工作,我对如何配置网络感到困惑。欢迎任何帮助。
谢谢。
【问题讨论】:
-
我用你的 Dockerfile 构建了一个镜像,它似乎可以工作:
firefox http://localhost:8000正确显示 Jupyter 登录。 -
问:你知道官方图片hub.docker.com/r/jupyterhub/jupyterhub吗?这记录在这个 GitHub 存储库中:github.com/jupyterhub/jupyterhub/blob/master/docs/source/…(顺便说一句,我不能 100% 确定在您的 CLI 示例中是否真的需要
-f jupyterhub_config.py) -
感谢您的 cmets @ErikMD,是的,我知道官方图像,但我需要对其进行自定义,它也适用于我的本地主机。我想部署它并从另一台计算机访问,我对网络配置感到困惑。最后,我看到了最后一个链接并尝试了 ip 和端口的所有配置,仍然无法从另一台计算机访问,而对于 docker 上的烧瓶应用程序我可以。
标签: docker jupyter jupyterhub