5

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

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

6 Comments

I get the following error, Step 13/17 : COPY start.sh /usr/local/bin/ COPY failed: stat /var/lib/docker/tmp/docker-builder157048403/start.sh: no such file or directory
If you use jupyter/base-notebook then start.sh is already there. Besides, always check if the file you want to copy is there in the first place.
ARG BASE_CONTAINER=jupyter/base-notebook FROM $BASE_CONTAINER ARG export_file=FooD_Kind.csv RUN pip install numpy RUN pip install matplotlib RUN pip install pandas RUN pip install pulp RUN fix-permissions /etc/jupyter/ COPY task_4kind.ipynb / COPY $export_file FooD_Kind.csv COPY task_4kind.ipynb / # 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/ ENTRYPOINT ["tini", "-g", "--"] CMD ["start-notebook.sh"] is this correct?
No. You already have the jupyter files you try to copy. Also, no need to modify the CMD or ENTRYPOINT. Check the example I linked.
ARG BASE_CONTAINER=jupyter/base-notebook FROM $BASE_CONTAINER MAINTAINER khan saab "[email protected]" ARG export_file=FooD_Kind.csv RUN pip install numpy RUN pip install matplotlib RUN pip install pandas RUN pip install pulp RUN fix-permissions /etc/jupyter/ ENTRYPOINT ["tini", "-g", "--"] CMD ["start-notebook.sh"] I can successfully build an image but the token is still giving invalid credentials error on localhost
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.