-- Why would I want to run a Jupyter notebook inside a container, when I have it installed right on my laptop?
This question is maybe the one you are asking now. Let me show you one common scenario I've faced: my OS (let's say mac OSX) is sometimes picky with some specific libraries I need to install, as requisites of some Python modules. So I need the modules, and the installation of these modules is not impossible, but painful. What do I do? Well, use a linux container, put what I need inside it, and then run a jupyter notebook from inside it, exposing my notebook on the local web browser.
This approach will save you some stress in tweaking your system libraries/configurations, and it is sustainable over time. To save your jupyter notebook simply mount a volume inside the container and work on that folder: it will persist on your machine after the container is terminated.
Here are the 3 simple steps to achieve it:
bash
, exposing a port you may like (here I'm using the common 8888). I'm also adding the --rm
argument to remove the name after it terminates: docker run -it -p 8888:8888 --rm image_name bash
jupyter notebook --ip 0.0.0.0 --no-browser
It will generate and print a token you'll need.localhost:8888/tree
on the url section. Here your token will be needed.That's all! you're running your notebook from inside the container, exposing it on your local browser!
Some additional tips:
%matplotlib notebook
or %matplotlib ipympl
This will make your plots more manageable... but this is personal taste.Dockerfile
, use a block like this:Hope this helps!
For ideas/comments you can tweet me or comment/message in instagram.