If you never heard about Jupyter Notebook, I highly recommend you to check it out. It have been my primary platform to build reports and data driven case studies. On this post I’d like to show how I create a simple and isolated environment with a Bash script and Docker to run JupyterLab.
JupyterLab is an interactive development environment for working with notebooks, code and data … JupyterLab has full support for Jupyter notebooks.
The major downside to this platform is its dependency on Python packages and versions, which is not a problem per se but can be annoying manage Python packages on my Mac - of course I could use VirtualEnv or Conda, but for me it seemed a little bit off.
I’ve been using Docker to aisle environments and guarantee builds and consistency among systems, even between our production server and my MacBook. Having notebooks with specific packages dependencies and Python version feels the kind of problem Docker can help us.
I love Docker and the simplicity it brings to the table - once you understand it and learn a few commands and best practices.
How it works
The launcher is quite simple, it register a function to:
1. Check the last modified attribute from the
2. Convert it to a human readable date, it will be the image tag.
3. Then look locally for an image using this same tag.
4. If there is no image available locally, build it using the new requirements.txt
5. Once the image is available locally, launch it, running on http://localhost:8888 and mapping the current folder as the notebook folder.
Install and Usage
Create a local folder and clone the repository, I’ve several similar hacks on this folder I intend to share in the future
1 2 3
Add this to your ~/.bashrc:
1 2 3
Now reload and you’re good to go:
1 2 3 4 5
After a few seconds you will see this:
1 2 3 4 5 6 7 8 9 10 11 12
Open your browser at http://0.0.0.0:8888/ and happy hacking :D
Improvements & variations
My idea was to create something that could be as transparent as possible, I like that
notebook command feels as if it is a local installed software, but there are room for improvements, like:
- Better error handling when Docker engine is not running.
- Find another tag strategy, instead of
git tagcould be a candidate. PR anyone? 🤓