|
1 | | -# OpEn Jupyter Notebook |
| 1 | +# OpEn JupyterLab Docker Image |
2 | 2 |
|
3 | | -Hmm.. that [OpEn](https://alphaville.github.io/optimization-engine/) framework looks really cool, but I'm too lazy to spend two minutes to [install](https://alphaville.github.io/optimization-engine/docs/installation) it! |
| 3 | +This directory contains the Docker image used to try OpEn quickly from a browser-based Python environment. |
4 | 4 |
|
5 | | -## TaDa... |
| 5 | +The current Dockerfile and Docker image version documented here is `0.6.0`. |
| 6 | +This image bundles the Python package `opengen==0.10.0`. |
6 | 7 |
|
7 | | -You can now download this docker image using |
| 8 | +## What is in the image? |
| 9 | + |
| 10 | +The image is built from `python:3.12-slim-bookworm` and contains: |
| 11 | + |
| 12 | +- Python 3.12 in a virtual environment at `/venv` |
| 13 | +- `opengen==0.10.0` |
| 14 | +- JupyterLab |
| 15 | +- Rust installed through `rustup` |
| 16 | +- Example notebooks copied into `/open/notebooks` |
| 17 | + |
| 18 | +## Pull and run the image |
8 | 19 |
|
9 | 20 | ```console |
10 | | -docker pull alphaville/open |
| 21 | +docker pull alphaville/open:0.6.0 |
| 22 | +docker run --name open-jupyter -p 127.0.0.1:8888:8888 -it alphaville/open:0.6.0 |
11 | 23 | ``` |
12 | 24 |
|
13 | | -and then run it with |
| 25 | +Open JupyterLab at: |
| 26 | + |
| 27 | +- `http://127.0.0.1:8888/lab` |
| 28 | + |
| 29 | +By default, the container starts with Jupyter's token authentication enabled. The token is printed in the container logs. |
| 30 | + |
| 31 | +To see the token: |
14 | 32 |
|
15 | 33 | ```console |
16 | | -docker run --name open-jupyter -p 8888:8888 -it alphaville/open |
| 34 | +docker logs open-jupyter |
17 | 35 | ``` |
18 | 36 |
|
19 | | -Note that this will create a docker container with name `open-jupyter`. If you stop it, you can restart it with (don't do `docker run` again) |
| 37 | +If you stop the container, restart it with: |
20 | 38 |
|
21 | 39 | ```console |
22 | 40 | docker start -ai open-jupyter |
23 | 41 | ``` |
24 | 42 |
|
25 | | -## What it does |
26 | | - |
27 | | -It starts a Jupyter Notebook at [localhost:8888](http://localhost:8888) without a password. |
| 43 | +## Password-based access |
28 | 44 |
|
29 | | -## What's in the docker image? |
| 45 | +To run JupyterLab with a password instead of the default token, provide a hashed password through `JUPYTER_NOTEBOOK_PASSWORD`. |
30 | 46 |
|
31 | | -This docker image is build from `debian:stable` and contains: |
32 | | - |
33 | | -- A virtual environment (with Python 3) |
34 | | -- Opengen [v0.8.0](https://github.com/alphaville/optimization-engine/releases/tag/opengen-0.8.0) |
35 | | -- The [latest version](https://crates.io/crates/optimization_engine) of the OpEn rust solver is installed automatically |
36 | | -- Jupyter notebook (runs automatically when the image runs) |
| 47 | +```console |
| 48 | +docker run \ |
| 49 | + --name open-jupyter \ |
| 50 | + -e JUPYTER_NOTEBOOK_PASSWORD=... \ |
| 51 | + -p 127.0.0.1:8888:8888 \ |
| 52 | + -it alphaville/open:0.6.0 |
| 53 | +``` |
37 | 54 |
|
| 55 | +For password hashing instructions, see the Jupyter documentation: |
38 | 56 |
|
39 | | -## How to open a terminal into the docker image |
| 57 | +- https://jupyter-server.readthedocs.io/en/latest/operators/public-server.html |
40 | 58 |
|
41 | | -Just |
| 59 | +## Working with notebooks |
42 | 60 |
|
43 | | -```console |
44 | | -docker exec -it open-jupyter bash |
45 | | -``` |
| 61 | +The bundled example notebook is stored in this repository under: |
46 | 62 |
|
47 | | -This will open a bash shell to the docker image with name `open-jupyter`; this is the name we specified above when we ran the image (using `--name open-jupyter`). In this bash shell, the virtual environment on which the Jupyter notebook is running is enabled by default. |
| 63 | +- `docker/notebooks/example.ipynb` |
48 | 64 |
|
| 65 | +Inside the container it is available under: |
49 | 66 |
|
50 | | -### How to run with specified volume |
| 67 | +- `/open/notebooks/example.ipynb` |
51 | 68 |
|
52 | | -Firstly, you need to create a volume. You only need to do this once (unless you want to create different volumes). As an example, let us create a docker volume with name `OpEnVolume`: |
| 69 | +To keep your own notebooks between container runs, mount a volume onto `/open`: |
53 | 70 |
|
54 | 71 | ```console |
55 | 72 | docker volume create OpEnVolume |
| 73 | +docker run --name open-jupyter \ |
| 74 | + --mount source=OpEnVolume,destination=/open \ |
| 75 | + -p 127.0.0.1:8888:8888 \ |
| 76 | + -it alphaville/open:0.6.0 |
56 | 77 | ``` |
57 | 78 |
|
58 | | -Next, let us run the image `alphaville/open:0.5.0` with the above volume: |
| 79 | +## Open a shell in the container |
59 | 80 |
|
60 | 81 | ```console |
61 | | -docker run --name open-jupyter \ |
62 | | - --mount source=OpEnVolume,destination=/open \ |
63 | | - -p 8888:8888 \ |
64 | | - -it alphaville/open:0.5.0 |
| 82 | +docker exec -it open-jupyter bash |
65 | 83 | ``` |
66 | 84 |
|
67 | | -## Set a password |
| 85 | +The virtual environment is available at `/venv`. |
68 | 86 |
|
69 | | -To set up a password for your Python Notebook: |
| 87 | +## Maintainer Notes |
70 | 88 |
|
71 | | -- [Hash your password](https://jupyter-notebook.readthedocs.io/en/stable/public_server.html#hashed-pw) |
72 | | -- Run your docker image with: |
| 89 | +Build the image from within the `docker/` directory: |
73 | 90 |
|
| 91 | +```console |
| 92 | +docker image build -t alphaville/open:0.6.0 . |
74 | 93 | ``` |
75 | | -docker run -e JUPYTER_NOTEBOOK_PASSWORD=... -p 8888:8888 -it alphaville/open |
| 94 | + |
| 95 | +You can also build it from the repository root: |
| 96 | + |
| 97 | +```console |
| 98 | +docker image build -t alphaville/open:0.6.0 -f docker/Dockerfile docker |
76 | 99 | ``` |
77 | 100 |
|
78 | | -For example, let's say you want to set the password **open**. Then do |
| 101 | +Before publishing, do a quick smoke test: |
79 | 102 |
|
80 | 103 | ```console |
81 | | -docker run \ |
82 | | - -e JUPYTER_NOTEBOOK_PASSWORD=sha1:898ca689bf37:2ee883bfd6ffe82a749a86e37964700bd06a2ff9 \ |
83 | | - -p 8888:8888 -it alphaville/open |
| 104 | +docker run --rm -p 127.0.0.1:8888:8888 alphaville/open:0.6.0 |
84 | 105 | ``` |
85 | 106 |
|
| 107 | +Then push the tag you built: |
86 | 108 |
|
| 109 | +```console |
| 110 | +docker push alphaville/open:0.6.0 |
| 111 | +``` |
| 112 | + |
| 113 | +If you want to check the bundled Python package version inside the image, run: |
| 114 | + |
| 115 | +```console |
| 116 | +docker run --rm --entrypoint /venv/bin/python alphaville/open:0.6.0 -c "from importlib.metadata import version; print(version('opengen'))" |
| 117 | +``` |
0 commit comments