From b1ffd94704169f6d62d1b5ce310ec92c0bafe878 Mon Sep 17 00:00:00 2001
From: Pantelis Sopasakis
Date: Mon, 25 Mar 2024 23:04:16 +0000
Subject: [PATCH 1/4] update Dockerfile
About:
Update dockerfile so that it runs
Deactivated externally-managed
TODO: use virtualenv
---
docker/Dockerfile | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/docker/Dockerfile b/docker/Dockerfile
index e3179b1e..09cdb7b2 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -19,8 +19,8 @@ FROM debian:stable
# Labels for the docker image
LABEL maintainer="Pantelis Sopasakis " \
- license="MIT license" \
- description="Jupyter notebook for Optimization Engine (OpEn)"
+ license="MIT license" \
+ description="Jupyter notebook for Optimization Engine (OpEn)"
WORKDIR /open
@@ -32,19 +32,20 @@ ENV PATH="/root/.cargo/bin:${PATH}"
# These commands are groupped into a separate RUN to faciliate
# caching; it is unlikely that any of the following will change
# in future versions of this docker image
-RUN "sh" "-c" "echo nameserver 8.8.8.8 >> /etc/resolv.conf" \
- && apt-get update -y \
+# "sh" "-c" "echo nameserver 8.8.8.8 >> /etc/resolv.conf"
+RUN apt-get update -y \
&& apt-get -y --no-install-recommends install \
- build-essential \
- curl \
- jupyter-notebook \
- python3 \
- python3-pip \
- python3-setuptools \
- && curl https://sh.rustup.rs -sSf | bash -s -- -y \
- && pip3 install wheel \
- && pip3 install opengen \
- && apt-get clean \
+ build-essential \
+ curl \
+ jupyter-notebook \
+ python3 \
+ python3-pip \
+ python3-setuptools
+RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
+RUN rm /usr/lib/python3.11/EXTERNALLY-MANAGED
+RUN pip3 install wheel
+RUN pip3 install opengen
+RUN apt-get clean \
&& rm -rf /var/lib/apt/lists/*
From aa20179e58b180831cb864c3514219be42657da2 Mon Sep 17 00:00:00 2001
From: Pantelis Sopasakis
Date: Tue, 26 Mar 2024 00:04:04 +0000
Subject: [PATCH 2/4] Docker runs on virtual env
---
docker/Dockerfile | 21 +++++++++++----------
docker/start_jupyter_notebook.sh | 4 ++--
2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 09cdb7b2..5c802a4e 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -32,7 +32,6 @@ ENV PATH="/root/.cargo/bin:${PATH}"
# These commands are groupped into a separate RUN to faciliate
# caching; it is unlikely that any of the following will change
# in future versions of this docker image
-# "sh" "-c" "echo nameserver 8.8.8.8 >> /etc/resolv.conf"
RUN apt-get update -y \
&& apt-get -y --no-install-recommends install \
build-essential \
@@ -40,21 +39,22 @@ RUN apt-get update -y \
jupyter-notebook \
python3 \
python3-pip \
- python3-setuptools
-RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
-RUN rm /usr/lib/python3.11/EXTERNALLY-MANAGED
-RUN pip3 install wheel
-RUN pip3 install opengen
-RUN apt-get clean \
- && rm -rf /var/lib/apt/lists/*
+ python3-setuptools \
+ python3-venv \
+ && curl https://sh.rustup.rs -sSf | bash -s -- -y \
+ && cd /; python3 -m venv venv \
+ && /bin/bash -c "source /venv/bin/activate && pip install wheel && pip install opengen && pip install jupyter" \
+ && apt-get clean \
+ && rm -rf /var/lib/apt/lists/* \
+ && echo "source /venv/bin/activate" >> /root/.bashrc
+EXPOSE 8888
# Run the following command every time this docker image
# is executed
COPY start_jupyter_notebook.sh /
RUN ["chmod", "+x", "/start_jupyter_notebook.sh"]
-ENTRYPOINT ["/start_jupyter_notebook.sh"]
-CMD ["/start_jupyter_notebook.sh"]
+CMD ["/bin/bash", "/start_jupyter_notebook.sh"]
@@ -65,4 +65,5 @@ CMD ["/start_jupyter_notebook.sh"]
#
# from within the base directory of this project.
#
+#
# ------------------------------------------------------------------------------
diff --git a/docker/start_jupyter_notebook.sh b/docker/start_jupyter_notebook.sh
index 4a2c6844..51604ac9 100644
--- a/docker/start_jupyter_notebook.sh
+++ b/docker/start_jupyter_notebook.sh
@@ -6,13 +6,13 @@ if [ -z "$JUPYTER_NOTEBOOK_PASSWORD" ]
then
echo "No Jupyter Notebook password provided - starting in unsafe mode"
echo "Set password using -e JUPYTER_NOTEBOOK_PASSWORD={sha of password}"
- jupyter notebook \
+ /venv/bin/jupyter notebook \
--port=8888 --no-browser \
--ip=0.0.0.0 --allow-root \
--NotebookApp.password='' --NotebookApp.token=''
else
echo "Jupyter Notebook password provided by user"
- jupyter notebook \
+ /venv/bin/jupyter notebook \
--port=8888 --no-browser \
--ip=0.0.0.0 --allow-root \
--NotebookApp.password=$JUPYTER_NOTEBOOK_PASSWORD
From aabbb65a5caa2bbd8669f15577273f95046b34f7 Mon Sep 17 00:00:00 2001
From: Pantelis Sopasakis
Date: Tue, 26 Mar 2024 00:13:23 +0000
Subject: [PATCH 3/4] docker: create volume
---
docker/Dockerfile | 1 +
1 file changed, 1 insertion(+)
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 5c802a4e..56a98733 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -23,6 +23,7 @@ LABEL maintainer="Pantelis Sopasakis " \
description="Jupyter notebook for Optimization Engine (OpEn)"
WORKDIR /open
+VOLUME /open
# Example Python notebook
COPY example.ipynb /open/
From 0ab34f7b1f3b2280b678a5ba21797f7d38067c33 Mon Sep 17 00:00:00 2001
From: Pantelis Sopasakis
Date: Tue, 26 Mar 2024 14:50:29 +0000
Subject: [PATCH 4/4] [ci skip] dockers docs (readme)
---
docker/README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 46 insertions(+), 2 deletions(-)
diff --git a/docker/README.md b/docker/README.md
index eaf02611..6c1def73 100644
--- a/docker/README.md
+++ b/docker/README.md
@@ -13,13 +13,57 @@ docker pull alphaville/open
and then run it with
```console
-docker run -p 8888:8888 -it alphaville/open
+docker run --name open-jupyter -p 8888:8888 -it alphaville/open
+```
+
+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)
+
+```console
+docker start -ai open-jupyter
```
## What it does
It starts a Jupyter Notebook at [localhost:8888](http://localhost:8888) without a password.
+## What's in the docker image?
+
+This docker image is build from `debian:stable` and contains:
+
+- A virtual environment (with Python 3)
+- Opengen [v0.8.0](https://github.com/alphaville/optimization-engine/releases/tag/opengen-0.8.0)
+- The [latest version](https://crates.io/crates/optimization_engine) of the OpEn rust solver is installed automatically
+- Jupyter notebook (runs automatically when the image runs)
+
+
+## How to open a terminal into the docker image
+
+Just
+
+```console
+docker exec -it open-jupyter bash
+```
+
+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.
+
+
+### How to run with specified volume
+
+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`:
+
+```console
+docker volume create OpEnVolume
+```
+
+Next, let us run the image `alphaville/open:0.5.0` with the above volume:
+
+```console
+docker run --name open-jupyter \
+ --mount source=OpEnVolume,destination=/open \
+ -p 8888:8888 \
+ -it alphaville/open:0.5.0
+```
+
## Set a password
To set up a password for your Python Notebook:
@@ -33,7 +77,7 @@ docker run -e JUPYTER_NOTEBOOK_PASSWORD=... -p 8888:8888 -it alphaville/open
For example, let's say you want to set the password **open**. Then do
-```
+```console
docker run \
-e JUPYTER_NOTEBOOK_PASSWORD=sha1:898ca689bf37:2ee883bfd6ffe82a749a86e37964700bd06a2ff9 \
-p 8888:8888 -it alphaville/open