Skip to content

Latest commit

 

History

History
149 lines (99 loc) · 4.12 KB

File metadata and controls

149 lines (99 loc) · 4.12 KB
id docker
title Docker
sidebar_label Docker
description Docker image of a JupyterLab environment to run OpEn

OpEn in Docker container

What is Docker?

Docker is a tool for packaging applications and their dependencies into containers. A container can run on different machines without requiring you to recreate the same environment manually.

What is JupyterLab?

According to jupyter.org, JupyterLab is a web-based development environment for notebooks, code, and data.

Requirements

You need to have Docker installed. See the official installation instructions.

Pull and Run the Docker Image

You can download the current Docker image using:

docker pull alphaville/open:0.6.0

and then run it with:

docker run --name open-jupyter -p 127.0.0.1:8888:8888 -it alphaville/open:0.6.0

This starts JupyterLab and makes it available at:

The image currently includes:

  • Python 3.12
  • opengen==0.10.0
  • JupyterLab
  • Rust installed through rustup
  • Example notebooks under /open/notebooks

By default, JupyterLab starts with token authentication enabled. To view the token:

docker logs open-jupyter

It is always a good idea to give your container a name using --name.

Info: Use docker run only the first time you create the container. Use docker start -ai open-jupyter to start it again later.
Tip: To stop a running container, do docker stop open-jupyter.

Configure the Docker Image

Configure password-based access

To run JupyterLab with a password instead of the default token, provide a hashed password through JUPYTER_NOTEBOOK_PASSWORD:

docker run \
  --name open-jupyter \
  -e JUPYTER_NOTEBOOK_PASSWORD='your hashed password' \
  -p 127.0.0.1:8888:8888 \
  -it alphaville/open:0.6.0

For password hashing instructions, see the Jupyter Server documentation.

How to set up a password

You can read more about how to set up a password for your Python notebook here. TL;DR: run the following command:

docker run --rm -it --entrypoint /venv/bin/python \
  alphaville/open:0.6.0 \
  -c "from jupyter_server.auth import passwd; print(passwd())"

You will be asked to provide your password twice. Then a string will be printed; this is your hashed password.

Configure port

You can access JupyterLab on a different host port by changing Docker's port forwarding. For example, to use port 80 on your machine:

docker run -p 80:8888 alphaville/open:0.6.0

Then JupyterLab will be available at http://localhost/lab.

Work with notebooks

The bundled example notebook is available inside the container at:

/open/notebooks/example.ipynb

To persist your own notebooks across container restarts, mount a Docker volume onto /open:

docker volume create OpEnVolume
docker run --name open-jupyter \
  --mount source=OpEnVolume,destination=/open \
  -p 127.0.0.1:8888:8888 \
  -it alphaville/open:0.6.0

Load additional Python packages

You can install additional packages from inside JupyterLab. For example:

!pip install matplotlib

Packages installed into a persistent container or volume-backed environment will still be there the next time you access it.

Open a terminal in the container

Suppose you have a running Docker container with name open-jupyter. To open a shell in it:

docker exec -it open-jupyter /bin/bash

The Python virtual environment is available at /venv.

Download your optimizer

To download a generated optimizer from JupyterLab, first create an archive:

!tar -cf rosenbrock.tar.gz optimizers/rosenbrock