Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode: How to run a Jupyter notebook in a docker container, over a remote server?

I can use the docker extension, and right click 'attach shell' to a running container. However, my Jupyter notebooks is not running in that container.

I tried googling how to run a jupyter notebook in a docker container, but I didn't get any results.

If it makes a difference, I am trying to run my notebook in a docker container on a remote server (using VS Code remote ssh to log in)

Edit:

I also tried running

!docker exec -ti {container name} bash

In jupyter, but that cell just hangs. When I stop the cell, the notebook still does not run in the container.

like image 253
SantoshGupta7 Avatar asked Sep 21 '20 19:09

SantoshGupta7


People also ask

Can you use Jupyter Notebook from remote server?

you can run jupyter notebook --no-browser --ip="<remote server ip>" on your remote machine terminal. And access notebooks using http://:8888/?token=<> from your browser on local machine.


Video Answer


1 Answers

Update 31.08.2022: The original approach now may cause Docker error:

standard_init_linux.go:228: exec user process caused: no such file or directory

Which is fixed if you're using system package instead of raw download from repo. In case of Ubuntu:

RUN apt-get install tini

the rest is the same:

RUN chmod +x /usr/bin/tini
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root"]

Just came to the same problem. It appeared that you cannot run Jupyter from a container out of the box. But this link helped me. Basically what you need is:

  1. Add this to your dockerfile:
# 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", "--"]
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root"]

This will start jupyter inside a container on port 8888. So don't forget to expose this port in your docker-compose or docker run.

This worked for me in my local docker. I can assume that for SSH docker you need to forward 8888 port during you SSH connection from remote to your local host.

like image 165
Jahjajaka Avatar answered Oct 19 '22 18:10

Jahjajaka