Start BeakerX using a context path in Docker
The notebook tool jupyter is a nice way to demo code or just having a playground for languages such as python which is supported by default. Even though python is supported by default you can install a plethora of additional kernels (here is an overview: Jupyter-kernels ). For simplicity reasons I looked for a docker image which covered most languages I am using and I got lucky: beakerx . As shown on their website launching this jupyter instance is quite easy:
docker run -p 8888:8888 beakerx/beakerx
The application can simply be accessed under http://localhost:8888 . However I wanted to put the server behind my traefik reverse proxy which required to use a context path for the application and unfortunately I couldn’t find any option for beakerx providing such a customization.
The solution is quite simple so I forked the report and created a pull request ( PR#8326 ). At this point it is unclear to me whether the development on beakerx still continues as the latest commits are quite old (also for the branches). That doesn’t change the fact that it’s still a very useful docker image but if you are here you might not wanna wait for an officially updated image, so create your own image:
- Create a folder for your extension. For this example we’re naming it patched_beakerx .
- Create a file patched_beakerx/Dockerfile with this content:
FROM beakerx/beakerx COPY jupyter_notebook_config.py /etc/jupyter
- This description just replicates the original image but adds a customized configuration to it.
- Create a file patched_beakerx/jupyter_notebook_config.py with this content:
# Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. import errno import os import stat import subprocess from jupyter_core.paths import jupyter_data_dir c = get_config() c.NotebookApp.ip = '0.0.0.0' c.NotebookApp.port = 8888 c.NotebookApp.open_browser = False # configure a path prefix for the app if it had been set if 'CONTEXT_PATH' in os.environ: c.NotebookApp.base_url = os.environ['CONTEXT_PATH'] # Generate a self-signed certificate if 'GEN_CERT' in os.environ: dir_name = jupyter_data_dir() pem_file = os.path.join(dir_name, 'notebook.pem') try: os.makedirs(dir_name) except OSError as exc: # Python >2.5 if exc.errno == errno.EEXIST and os.path.isdir(dir_name): pass else: raise # Generate a certificate if one doesn't exist on disk subprocess.check_call(['openssl', 'req', '-new', '-newkey', 'rsa:2048', '-days', '365', '-nodes', '-x509', '-subj', '/C=XX/ST=XX/L=XX/O=generated/CN=generated', '-keyout', pem_file, '-out', pem_file]) # Restrict access to the file os.chmod(pem_file, stat.S_IRUSR | stat.S_IWUSR) c.NotebookApp.certfile = pem_file
- This configuration file is essentially a copy of the original one with the difference that it sets the option c.NotebookApp.base_url if the environment variable CONTEXT_PATH had been set.
- Now build your new image assuming you changed into this directory (the tag is just an example):
docker build -t mycompany/beakerx_path .
If the image had been built successfully you can run it like this:
docker run -p 8888:8888 -e CONTEXT_PATH=beakerx beakerx/beakerx
This makes the full application accessible using http://localhost:8888/beakerx and thus easily manageable by any reverse proxy.