Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problem running docker image using jupyter notebook

Tags:

I have a jupyter notebook and a data file in a folder. I made a Dockerfile and wrote the following lines

FROM jupyter/base-notebook

ARG export_file=FooD_Kind.csv

RUN pip install jupyter

RUN pip install numpy

RUN pip install matplotlib

RUN pip install pandas

RUN pip install pulp

COPY $export_file FooD_Kind.csv

COPY task_4kind.ipynb /

CMD ["jupyter notebook", "task_4kind.ipynb"]

I can successfully build an image using docker build -t nameofimage But when I do docker run -it nameofimage. I get an error [FATAL tini (7)] exec jupyter notebook failed: No such file or directory .

How do I run this jupyter notebook in docker?

EDIT:

I tried two replacements on the last line,
I replaced the last line with

# Start the jupyter notebook
ENTRYPOINT ["jupyter", "notebook", "--ip=*"]

It runs and gives a token on the screen but when I paste the token on localhost, It gives invalid credentials error

then I replaced the last line with

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

It runs and gives a token on the screen but when I paste the token on localhost, It gives invalid credentials error

like image 696
Khaned Avatar asked Apr 28 '19 20:04

Khaned


1 Answers

If you check the original Dockerfile, you will find the following;

ENTRYPOINT ["tini", "-g", "--"]
CMD ["start-notebook.sh"]

# Add local files as late as possible to avoid cache busting
COPY start.sh /usr/local/bin/
COPY start-notebook.sh /usr/local/bin/
COPY start-singleuser.sh /usr/local/bin/

start-notebook.sh will get you a valid token. Subsequent files allow to interact with the image, these options are described in the docs.

Mind that there are more caveats, e.g. which user is running commands described in Dockerfile: root or jovyan (Jupyter user)? Commands executed by root may set permissions in a way that won't allow jovyan to e.g. load given package. To fix this, there's an extra line in all Jupyter (base notebook and derived) Dockerfiles:

RUN fix-permissions /etc/jupyter/

Here is an example how a derived notebook could look like.

In essence, either remove your custom ENTRYPOINT / CMD and use the original ones or make sure you e.g. get the token right. Also, fix permissions.

like image 175
Lukasz Tracewski Avatar answered Oct 10 '22 11:10

Lukasz Tracewski