Deploying Docker container#
To be able to deploy and run the OpenQuake Engine Docker container you need at least Docker version 1.10.
A basic knowledge about Docker and how this kind of application containers work is also required. For more information about operating system support (which includes Linux, macOS and specific versions of Windows) and on how to install Docker, please refer to the official Docker website.
Features provided#
Each container includes:
Python 3.13 from the official Docker image (for the nightly image; release and LTS images may ship a different Python version)
Python dependencies (numpy, scipy, h5py…)
OpenQuake Engine
The
oqcommand line toolThe OpenQuake WebUI and API server (by default listening on port 8800)
Deployment#
Docker single node deployment#
Pull an image from Docker Hub (see available-tags):
$ docker pull docker.io/openquake/engine[:TAG]
Headless mode#
This modality is recommended when only the WebUI or the API server is used (for example as the backend for the OpenQuake QGIS plugin).
$ docker run --name <containername> -d -p 127.0.0.1:8800:8800 openquake/engine:nightly
You can show the logs of the container running:
$ docker logs <containername> --timestamp --follow
After the logs show that the WebUI has started (and, if authentication is enabled, after the necessary migrations have been applied),
then you can connect to http://127.0.0.1:8800 to be able to access the WebUI or the API server
(if WEBUI_PATHPREFIX is set, connect to http://127.0.0.1:8800${WEBUI_PATHPREFIX}/engine/ instead).
You can stop and start again your container with the following commands:
$ docker stop <containername>
$ docker start <containername>
TTY mode#
This modality provides the same features as the headless mode plus the ability to drive the OpenQuake Engine via the oq command on a terminal.
$ docker run --name <containername> -t -i -p 127.0.0.1:8800:8800 openquake/engine:nightly
The container prompt will appear, and you will have the possibility to run oq via the command line interface.
INFO:root:Creating the initial schema from 0000-base_schema.sql
INFO:root:Creating the versioning table revision_info
INFO:root:Executing /usr/src/oq-engine/openquake/server/db/schema/upgrades/0001-job.sql
INFO:root:Executing /usr/src/oq-engine/openquake/server/db/schema/upgrades/0003-output.sql
INFO:root:Executing /usr/src/oq-engine/openquake/server/db/schema/upgrades/0004-job.sql
INFO:root:Executing /usr/src/oq-engine/openquake/server/db/schema/upgrades/0005-index.sql
INFO:root:Executing /usr/src/oq-engine/openquake/server/db/schema/upgrades/0006-checksum.sql
INFO:root:Executing /usr/src/oq-engine/openquake/server/db/schema/upgrades/0007-job.sql
INFO:root:Executing /usr/src/oq-engine/openquake/server/db/schema/upgrades/0008-job-tag.sql
INFO:root:Executing /usr/src/oq-engine/openquake/server/db/schema/upgrades/0009-workflow.sql
INFO:root:Upgrade completed in 1.2584140300750732 seconds
openquake@a4e28beda784:~$ oq --version
3.25.0
After you have restarted you container (same commands as the headless mode) you can re-attach the container shell using:
$ docker attach <containername>
[openquake@b318358ee053 ~]$
Remove a container or an image#
To destroy a container, type:
$ docker rm <containername>
To remove its image:
$ docker rmi openquake/<imagename>[:TAG]
You can print the list of containers and images using $ docker ps -a and $ docker images. For more details please refer to the official Docker documentation.
Docker advanced options#
Environment Variables#
The OpenQuake image uses the following environment variables with the default
Django settings. A custom local_settings.py, placed in the container as
/home/openquake/local_settings.py, can override the Django settings defined
by these variables, except for OQ_APPLICATION_MODE, which takes precedence
over local settings. The OQ_ADMIN_* variables are read only by the startup
script, and DJANGO_SETTINGS_MODULE selects the settings module itself, so
local_settings.py cannot replace them.
OQ_APPLICATION_MODE
This optional variable overrides the WebUI APPLICATION_MODE (PUBLIC by default, running the WebUI without authentication). If it is set to RESTRICTED, the authentication infrastructure will be enabled, restricting the access to authorized users.
OQ_ALLOWED_HOSTS
The comma-separated host names used to reach the WebUI (e.g. example.org,localhost,127.0.0.1). It is required when OQ_APPLICATION_MODE is RESTRICTED: with authentication enabled the WebUI refuses to start without it, since the links sent by email, e.g. to reset a password, are built from the host of the request.
OQ_ADMIN_USERNAME
In RESTRICTED mode, this variable defines the WebUI superuser username.
When it is unset or empty, the startup script uses the username admin.
OQ_ADMIN_PASSWORD
This variable sets the WebUI superuser password. When it is unset or empty,
the startup script generates a random password and prints it once in the
container log (docker logs <containername>), in a line starting with
Created the WebUI superuser.
OQ_ADMIN_EMAIL
This variable sets the WebUI superuser email. When it is unset or empty, the
startup script uses admin@example.com.
On each startup in RESTRICTED mode, the script creates a superuser if the
specified username does not exist yet; otherwise it only prints a line
saying that the superuser already exists. If you reuse the database (e.g. with
a persistent oqdata volume), changing OQ_ADMIN_USERNAME to a new username
creates another superuser. For an existing username, changing
OQ_ADMIN_PASSWORD or OQ_ADMIN_EMAIL has no effect: update the existing
user through the WebUI or Django admin instead.
WEBUI_PATHPREFIX
This variable sets an optional prefix before the WebUI route /engine/.
It is empty by default; for example, /path makes the route /path/engine/.
EMAIL_BACKEND
This variable specifies the backend used by Django to send emails. In
RESTRICTED mode it defaults to django.core.mail.backends.smtp.EmailBackend.
With this backend, EMAIL_HOST, EMAIL_PORT and EMAIL_PASS must be
set, otherwise the WebUI refuses to start; EMAIL_PASS may be set to an
empty value (EMAIL_PASS=) for an SMTP server that does not require
authentication. Without an SMTP server, set
EMAIL_BACKEND=django.core.mail.backends.console.EmailBackend: emails are
then printed on the WebUI output (docker logs <containername>, or
~/oqdata/webui.log in TTY mode) instead of being sent.
EMAIL_HOST
This variable specifies the host to use for sending emails (e.g. smtp.gmail.com)
EMAIL_PORT
This variable specifies the port to use for the SMTP server defined in EMAIL_HOST
EMAIL_USE_TLS
This variable specifies whether to use a TLS (secure) connection when talking to the SMTP server. This is used for explicit TLS connections, generally on port 587
EMAIL_USER
This variable sets Django’s EMAIL_HOST_USER setting, the username for the
SMTP server. It is also used as the sender (From) address of the password
reset emails, of the emails sent when a user is created with the
createuser Django management command (the startup script creates the
superuser without sending any email) and of the calculation notifications,
which are sent only in the AELO and IMPACT modes, so it must be a valid email
address accepted by the SMTP server. In RESTRICTED mode it defaults to
noreply@openquake.org.
To send the password reset emails from a different address, set Django’s
DEFAULT_FROM_EMAIL setting in local_settings.py.
EMAIL_PASS
This variable sets Django’s EMAIL_HOST_PASSWORD setting, the SMTP password.
The environment variables EMAIL_HOST_USER and EMAIL_HOST_PASSWORD are
not read by the default settings; use EMAIL_USER and EMAIL_PASS instead.
EMAIL_SUPPORT
This variable specifies the reply-to address of the calculation notifications, which are sent only in the AELO and IMPACT modes, so it is not used in RESTRICTED mode.
DJANGO_SETTINGS_MODULE
This variable specifies the path to the python module containing Django settings, formatted in Python path syntax, e.g. mysite.settings. Note that the settings module should be on the Python sys.path.
For example, configure restricted mode and SMTP in a .env file. Replace the
example values with your own; Docker’s --env-file passes quotation marks as
part of the value, so do not quote the values:
OQ_APPLICATION_MODE=RESTRICTED
OQ_ALLOWED_HOSTS=localhost,127.0.0.1
OQ_ADMIN_USERNAME=example
OQ_ADMIN_PASSWORD=replace-with-a-strong-password
OQ_ADMIN_EMAIL=login@example.com
EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
EMAIL_HOST=smtp.example.com
EMAIL_PORT=587
EMAIL_USE_TLS=true
EMAIL_USER=login@example.com
EMAIL_PASS=replace-with-the-smtp-password
EMAIL_SUPPORT=support@example.com
DJANGO_SETTINGS_MODULE=openquake.server.settings
To run the docker (replacing PATH with the path to the directory containing the .env file):
$ docker run --name <containername> -d -p 127.0.0.1:8800:8800 --env-file PATH/.env openquake/engine:nightly
This example runs a container named <containername> using the openquake/engine:nightly image, and sets the value for the environment variables.
This binds port 8800 of the container to TCP port 8800 on 127.0.0.1 of the host machine, so the WebUI is reachable from the host machine using the url: http://127.0.0.1:8800/engine.
If WEBUI_PATHPREFIX is set to /path, the WebUI is reachable at
http://127.0.0.1:8800/path/engine/ instead.
You can show the logs of the container running:
$ docker logs <containername> --timestamp --follow
After the logs show that the WebUI has started (and, if authentication is enabled, after the necessary migrations have been applied),
then you can connect to http://127.0.0.1:8800 to be able to access the WebUI or the API server
(if WEBUI_PATHPREFIX is set, connect to http://127.0.0.1:8800${WEBUI_PATHPREFIX}/engine/ instead).
Getting help#
If you need help or have questions/comments/feedback for us, you can subscribe to the OpenQuake users mailing list.