Skip to content

Commit a22bd12

Browse files
authored
Merge pull request #340 from alphaville/feature/update-docker-img
Update docker image
2 parents 00d195e + 0ab34f7 commit a22bd12

File tree

3 files changed

+68
-21
lines changed

3 files changed

+68
-21
lines changed

docker/Dockerfile

+20-17
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ FROM debian:stable
1919

2020
# Labels for the docker image
2121
LABEL maintainer="Pantelis Sopasakis <[email protected]>" \
22-
license="MIT license" \
23-
description="Jupyter notebook for Optimization Engine (OpEn)"
22+
license="MIT license" \
23+
description="Jupyter notebook for Optimization Engine (OpEn)"
2424

2525
WORKDIR /open
26+
VOLUME /open
2627

2728
# Example Python notebook
2829
COPY example.ipynb /open/
@@ -32,28 +33,29 @@ ENV PATH="/root/.cargo/bin:${PATH}"
3233
# These commands are groupped into a separate RUN to faciliate
3334
# caching; it is unlikely that any of the following will change
3435
# in future versions of this docker image
35-
RUN "sh" "-c" "echo nameserver 8.8.8.8 >> /etc/resolv.conf" \
36-
&& apt-get update -y \
36+
RUN apt-get update -y \
3737
&& apt-get -y --no-install-recommends install \
38-
build-essential \
39-
curl \
40-
jupyter-notebook \
41-
python3 \
42-
python3-pip \
43-
python3-setuptools \
44-
&& curl https://sh.rustup.rs -sSf | bash -s -- -y \
45-
&& pip3 install wheel \
46-
&& pip3 install opengen \
47-
&& apt-get clean \
48-
&& rm -rf /var/lib/apt/lists/*
38+
build-essential \
39+
curl \
40+
jupyter-notebook \
41+
python3 \
42+
python3-pip \
43+
python3-setuptools \
44+
python3-venv \
45+
&& curl https://sh.rustup.rs -sSf | bash -s -- -y \
46+
&& cd /; python3 -m venv venv \
47+
&& /bin/bash -c "source /venv/bin/activate && pip install wheel && pip install opengen && pip install jupyter" \
48+
&& apt-get clean \
49+
&& rm -rf /var/lib/apt/lists/* \
50+
&& echo "source /venv/bin/activate" >> /root/.bashrc
4951

52+
EXPOSE 8888
5053

5154
# Run the following command every time this docker image
5255
# is executed
5356
COPY start_jupyter_notebook.sh /
5457
RUN ["chmod", "+x", "/start_jupyter_notebook.sh"]
55-
ENTRYPOINT ["/start_jupyter_notebook.sh"]
56-
CMD ["/start_jupyter_notebook.sh"]
58+
CMD ["/bin/bash", "/start_jupyter_notebook.sh"]
5759

5860

5961

@@ -64,4 +66,5 @@ CMD ["/start_jupyter_notebook.sh"]
6466
#
6567
# from within the base directory of this project.
6668
#
69+
#
6770
# ------------------------------------------------------------------------------

docker/README.md

+46-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,57 @@ docker pull alphaville/open
1313
and then run it with
1414

1515
```console
16-
docker run -p 8888:8888 -it alphaville/open
16+
docker run --name open-jupyter -p 8888:8888 -it alphaville/open
17+
```
18+
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)
20+
21+
```console
22+
docker start -ai open-jupyter
1723
```
1824

1925
## What it does
2026

2127
It starts a Jupyter Notebook at [localhost:8888](http://localhost:8888) without a password.
2228

29+
## What's in the docker image?
30+
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)
37+
38+
39+
## How to open a terminal into the docker image
40+
41+
Just
42+
43+
```console
44+
docker exec -it open-jupyter bash
45+
```
46+
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.
48+
49+
50+
### How to run with specified volume
51+
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`:
53+
54+
```console
55+
docker volume create OpEnVolume
56+
```
57+
58+
Next, let us run the image `alphaville/open:0.5.0` with the above volume:
59+
60+
```console
61+
docker run --name open-jupyter \
62+
--mount source=OpEnVolume,destination=/open \
63+
-p 8888:8888 \
64+
-it alphaville/open:0.5.0
65+
```
66+
2367
## Set a password
2468

2569
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
3377

3478
For example, let's say you want to set the password **open**. Then do
3579

36-
```
80+
```console
3781
docker run \
3882
-e JUPYTER_NOTEBOOK_PASSWORD=sha1:898ca689bf37:2ee883bfd6ffe82a749a86e37964700bd06a2ff9 \
3983
-p 8888:8888 -it alphaville/open

docker/start_jupyter_notebook.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ if [ -z "$JUPYTER_NOTEBOOK_PASSWORD" ]
66
then
77
echo "No Jupyter Notebook password provided - starting in unsafe mode"
88
echo "Set password using -e JUPYTER_NOTEBOOK_PASSWORD={sha of password}"
9-
jupyter notebook \
9+
/venv/bin/jupyter notebook \
1010
--port=8888 --no-browser \
1111
--ip=0.0.0.0 --allow-root \
1212
--NotebookApp.password='' --NotebookApp.token=''
1313
else
1414
echo "Jupyter Notebook password provided by user"
15-
jupyter notebook \
15+
/venv/bin/jupyter notebook \
1616
--port=8888 --no-browser \
1717
--ip=0.0.0.0 --allow-root \
1818
--NotebookApp.password=$JUPYTER_NOTEBOOK_PASSWORD

0 commit comments

Comments
 (0)