Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docker image #340

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 20 additions & 17 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ FROM debian:stable

# Labels for the docker image
LABEL maintainer="Pantelis Sopasakis <p.sopasakis@gmail.com>" \
license="MIT license" \
description="Jupyter notebook for Optimization Engine (OpEn)"
license="MIT license" \
description="Jupyter notebook for Optimization Engine (OpEn)"

WORKDIR /open
VOLUME /open

# Example Python notebook
COPY example.ipynb /open/
Expand All @@ -32,28 +33,29 @@ 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 \
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 \
&& rm -rf /var/lib/apt/lists/*
build-essential \
curl \
jupyter-notebook \
python3 \
python3-pip \
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"]



Expand All @@ -64,4 +66,5 @@ CMD ["/start_jupyter_notebook.sh"]
#
# from within the base directory of this project.
#
#
# ------------------------------------------------------------------------------
48 changes: 46 additions & 2 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docker/start_jupyter_notebook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down