Compose is a tool for defining and running multi-container Docker applications.
Install compose https://docs.docker.com/compose/install/
Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.
...
Steps for setting up OpenSRP docker container
Checkout opensrp docker builds and navigate to the composed directory.
Below is the list of build time args
No Format |
---|
#Build arguments
ARG opensrp_server_tag
#openmrs settings
ARG openmrs_url="http:\/\/localhost:8080\/openmrs\/"
ARG openmrs_username=admin
ARG openmrs_password=Admin123
#couchdb settings
ARG couchdb_username
ARG couchdb_password
ARG couchdb_opensrp_db=opensrp
ARG couchdb_form_db=opensrp-form
ARG couchdb_atomfeed_db=atomfeed
ARG couchdb_mcts_db=opensrp-mcts
ARG couchdb_motech_db=motech-scheduletracking-api
ARG couchdb_error_db=opensrp-errortrace
#mysql settings
ARG mysql_opensrp_user
ARG mysql_opensrp_password
ARG mysql_opensrp_database
ARG mysql_openmrs_user
ARG mysql_openmrs_password
ARG mysql_openmrs_database
ARG mysql_motech_database
ARG mysql_reporting_database
ARG mysql_anm_database
ARG mysql_opensrp_jdbc="jdbc:mysql:\/\/mysql:3306\/${mysql_opensrp_database}?createDatabaseIfNotExist=true"
ARG mysql_opensrp_jdbc_wo="jdbc:mysql:\/\/mysql:3306"
ARG mysql_motech_jdbc="jdbc:mysql:\/\/mysql:3306\/${mysql_motech_database}"
#redis settings
ARG redis_password
#postgres settings
ARG postgres_opensrp_user
ARG postgres_opensrp_password
ARG postgres_opensrp_database
ARG postgres_opensrp_jdbc="jdbc:postgresql:\/\/postgres:5432\/${postgres_opensrp_database}"
ARG demo_data_tag |
Create .env file to store variables and credentials. For example, create a file with the following details..
No Format |
---|
#!/bin/sh
POSTGRES_OPENSRP_TABLESPACE_DIR=/opt/postgresql
POSTGRES_OPENSRP_DATABASE=opensrp
POSTGRES_OPENSRP_USER=opensrp_admin
POSTGRES_OPENSRP_PASSWORD=admin
MYSQL_ROOT_PASSWORD=mypassword
MYSQL_MOTECH_DATABASE=motechquartz
MYSQL_REPORTING_DATABASE=report
MYSQL_ANM_DATABASE=anm
MYSQL_OPENMRS_USER=openmrs
MYSQL_OPENMRS_PASSWORD=openmrs
MYSQL_OPENMRS_DATABASE=openmrs
MYSQL_OPENSRP_USER=opensrp
MYSQL_OPENSRP_PASSWORD=opensrp
MYSQL_OPENSRP_DATABASE=opensrp
COUCHDB_USER=rootuser
COUCHDB_PASSWORD=adminpass
REDIS_PASSWORD=reallylongreallylongpassword
OPENSRP_SERVER_TAG=opensrp_server_tag |
...
No Format |
---|
migrations:
build:
context: .
dockerfile: ./Dockerfile
args:
- custom_build_arg=${MY_ARG} |
Run compose up
No Format |
---|
docker-compose up -d |
Alternatively if you want to rebuild the containers use
No Format |
---|
docker-compose up --force-recreate --remove-orphans --build -d |
...
Link couchdb with lucene.
Go to couchdb container
No Format |
---|
docker exec -it composed_couchdb_1 bash |
update /usr/local/etc/couchdb/local.ini i.e. append the following lines
No Format | ||
---|---|---|
| ||
[couchdb]
os_process_timeout=60000 ; increase the timeout from 5 seconds.
[external]
fti=/usr/bin/python /opt/couchdb-lucene/tools/couchdb-external-hook.py
[httpd_db_handlers]
_fti = {couch_httpd_external, handle_external_req, <<"fti">>}
[httpd_global_handlers]
_fti = {couch_httpd_proxy, handle_proxy_req, <<"http:\\couchdb-lucene:5985">>} |
NB: Checkout Cloudant Sync Security Configuration to configure couchdb security.
Test the services
...
Some useful commands
...
docker-compose down
...
docker volume rm composed_opensrp_couchdb_lucene \
composed_opensrp_couchdb composed_opensrp_migrations \
composed_opensrp_mysql composed_opensrp_postgres \
composed_opensrp_postgres_tablespaces composed_opensrp_redis
...
Note: Install docker CE or EE version. Docker CS is not supported and permission errors may be experienced if using Docker CS version.
Docker CS (Commercially Supported) is kind of the old bundle version of Docker EE for versions <= 1.13.
How to use the OpenSRP server web docker image?
OpenSRP server web docker image is published on dockerhub and github container registry.
Prerequisites
For OpenSRP to work it needs the following applications/services to support it and in brackets are their respective spring profiles that activate them (Default spring profiles are jedis,postgres and oauth2
):
Code Block |
---|
1. Redis (`jedis` profile)
2. Postgres (`postgres` profile)
3. Keycloak or Openmrs for (v2.1.* tags for openmrs sync, `openmrs-sync` profile) authentication is by default oauth2 but basic auth is still available for openmrs authentication with (`basic_auth` profile) |
To update the active profiles make changes on this line (comma separated) and include the file on the volumes section of docker compose.
OpenSRP server is deployed as a .war file. Its main configurations are stored in the following locations:
The depending on your setup one needs to modify the following files and mount them as volumes on the docker containers. The context.xml, keycloak.json and opensrp.properties must be updated.
Holds the postgres DB configurations e.g credentials, database name and other additional configs.
Copy this file and update the postgres credentials.
Holds mappings between URL paths and the servlets that handle requests with those paths, also the active spring profiles.
Unless one need additional spring maven profiles other than defaults there is no need to copy and update configuration.
Additional profiles can be added on this line.
Holds the logging configurations.
Unless one needs to customize log configurations leave as is.
Holds all the application properties config.
Copy the file and update applications configurations for redis, rabbitmq, openmrs, dhis2, threading, metrics, sentry just to name a few.
Change only what one needs and leave the rest as defaults.
Additionally update cors here to * for developments purposes or comma separated links of trusted origins.
keycloak.json
Holds all the keycloak configs used on spring.
Code Block { "auth-server-url": "https://<keycloak-url>/auth/", "confidential-port": 443, "credentials": { "secret": "<sample-secret>" }, "realm": "<realm name>", "resource": "<resource name>", "ssl-required": "external" }
Mybatis In-App Migration
Mybatis runtime configuration has been added from v2.10.x, v3.2.x, v2.1.7x meaning migrations will run when during application start up.
Now using the image.
Code Block |
---|
version: "3.9"
services:
redis:
restart: unless-stopped
image: redis:6.0
ports:
- "6379:6379"
command: redis-server --requirepass redisPassword # update with an appropriate password.
volumes:
- redisdata:/data
postgres:
restart: unless-stopped
image: postgres:14
ports:
- "5457:5432"
environment:
- "POSTGRES_PASSWORD=mysecretpassword"
- "POSTGRES_USER=postgres"
- "POSTGRES_DB=postgres"
volumes:
- pgdata:/var/lib/postgresql/data
# Remove keycloak service if openmrs is used for authentication
keycloak:
restart: unless-stopped
image: jboss/keycloak:16.1.1
environment:
- "KEYCLOAK_USER=admin"
- "KEYCLOAK_PASSWORD=admin"
- "DB_VENDOR=postgres"
- "DB_PASSWORD=secretpassword"
- "DB_USER=keycloak"
- "DB_ADDR=postgres:5432"
- "PROXY_ADDRESS_FORWARDING=true"
ports:
- "8081:8080"
- "8443:8443"
depends_on:
- postgres
opensrp-server-web:
restart: unless-stopped
image: opensrp/opensrp-server-web:v2.10.0-SNAPSHOT # pick the latest tag
ports:
- "8080:8080"
volumes:
- ./context.xml:/usr/local/tomcat/webapps/opensrp/META-INF/context.xml
- ./opensrp.properties:/usr/local/tomcat/webapps/opensrp/WEB-INF/classes/opensrp.properties
- ./keycloak.json:/usr/local/tomcat/webapps/opensrp/WEB-INF/keycloak.json
- multimediaData:/opt/multimedia
depends_on:
- keycloak
- redis
# refer to https://hub.docker.com/r/opensrp/web
# opensrp-web:
# depends_on:
# - opensrp-server-web
volumes:
redisdata:
# external: true
pgdata:
# external: true
multimediaData:
# external: true
|
And to run it
Code Block |
---|
docker-compose up |
For production setups consider backing up the postgresql databases.
References
https://docs.docker.com/compose/
https://docs.docker.com/compose/networking/
https://hub.docker.com/_/mysql/
https://hub.docker.com/_/couchdb/
https://github.com/klaemo/docker-couchdb-lucene