Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to connect to Jupyter Notebook served by Docker

I've been learning Docker with the end goal of using it to serve up and share Jupyter Notebooks. Below is an example Dockerfile:

FROM python:2
ENV PYTHONUNBUFFERRED 1
RUN pip install jupyter

RUN useradd --create-home --home-dir /home/docker --shell /bin/bash docker
RUN adduser docker sudo

ADD start.sh /home/docker/start.sh
RUN chmod +x /home/docker/start.sh
RUN chown docker /home/docker/start.sh

ADD prod_sentiment.ipynb /home/docker/prod_sentiment.ipynb
ADD output.txt /home/docker/output.txt
RUN chmod +x /home/docker/output.txt
RUN chown docker /home/docker/output.txt

EXPOSE 8888
RUN usermod -a -G sudo docker
RUN echo "docker ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
USER docker

ENV HOME=/home/docker
ENV SHELL=/bin/bash
ENV USER=docker

RUN printenv
CMD ./home/docker/start.sh

The start.sh file looks as such:

#! /bin/sh
echo 'starting'
nohup jupyter notebook --no-browser > /home/docker/output.txt

I then:

docker build --rm -t 'test' .
docker run -d -ti -p 8888:8888 test

From this point, I would presume I should be able to navigate to localhost:8888 and see the Jupyter Notebook. If I connect to the container via: docker exec -i -t container_id /bin/bash I can tail -f /home/docker/output.txt to see that I can curl it from within the Docker container. Likewise ps auwx | grep 'jupyter' confirms the Jupyter Notebook webserver is running.

Beyond binding the port as such 8888:8888 and EXPOSING it in the Dockerfile, what am I missing? Whenever I connect to http://localhost:8888 it says 'localhost didn't send any data'.

I'm using Docker for Mac Version 1.12.1-beta26.1 build 1200.

like image 698
Lorena Nicole Avatar asked Sep 27 '16 20:09

Lorena Nicole


1 Answers

Your issue is that jupyter is only listening on the loopback interface by default. You can change this by running jupyter with the option --ip=0.0.0.0 which will cause it to bind on all interfaces (inside the container).

EDIT: There is also some more information on this in the jupyter documentation. Plus an example they provide in that documentation:

# Add Tini. Tini operates as a process subreaper for jupyter. This prevents
# kernel crashes.
ENV TINI_VERSION v0.6.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini
RUN chmod +x /usr/bin/tini
ENTRYPOINT ["/usr/bin/tini", "--"]

EXPOSE 8888
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0"]
like image 119
joelnb Avatar answered Oct 21 '22 11:10

joelnb