Home:ALL Converter>access jupyterhub on docker from external network

access jupyterhub on docker from external network

Ask Time:2019-10-02T23:37:48         Author:user1265067

Json Formatter

Docker is fairly new to me, I'm creating a jupyterhub container like that

FROM ubuntu:18.04
LABEL maintainer="Jupyter Project <[email protected]>"

# 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"]

with the following configuration file, base on 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'

Then I do:

docker run -i -p 8000:8000 --name jupyterhub jupyterhub:latest jupyterhub -f jupyterhub_config.py

It works as expected on my internal network, but I can't access it externally. If I do:

my_ip:8000

I can't connect.

For my Flask apps running on docker, all I do is to run the app in a 0.0.0.0 ip and it works, I'm confused here on how to configure the network. Any help would be welcome.

Thanks.

Author:user1265067,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58204831/access-jupyterhub-on-docker-from-external-network
Ryabchenko Alexander :

You can configure nginx on localhost, witch will proxy requests from external world for port that will listen to local port with your expose in your docker container \n\nserver {\n\n server_name <your_ip>;\n location / {\n proxy_pass http://0.0.0.0:8000;\n }\n listen 7000; \n}\n\n\nnow you can open <your_ip>:7000 from external ",
2019-10-05T18:02:36
yy