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.
Service | Current | New |
---|---|---|
mysql | localhost:3306 | mysql:3306 |
couchdb | localhost:5984 | couchdb:5984 |
couchdb-lucene | localhost:5985 | couchdb-lucene:5985 |
activemq | localhost:61616 | activemq:61616 |
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#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..
#!/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
These environment variables are used at runtime and also as build time arguments when building docker images for opensrp-composed and migrations containers.
Note: You can add an optional DEMO_DATA_TAG environment variable so that the launched containers contains demo(seed) data for a particular project. The value should be either zeir, tbreach or uganda-hpv. If the environment variable is set openmrs database, opensrp database and images will be downloaded from S3 bucket.
Note: If you want to override a build argument with a default constant expose it in the args section of a service in the docker compose file. To expose a build argument called custom_build_arg that is populated from MY_ARG environment variable, see the below examplemigrations: build: context: . dockerfile: ./Dockerfile args: - custom_build_arg=${MY_ARG}
Run compose up
docker-compose up -d
Alternatively if you want to rebuild the containers use
docker-compose up --force-recreate --remove-orphans --build -d
Link couchdb with lucene.
Go to couchdb containerdocker exec -it composed_couchdb_1 bash
update /usr/local/etc/couchdb/local.ini i.e. append the following lines
[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
Service Link Credentials OpenSRP http://localhost:9090/opensrp OpenMRS http://localhost:9090/openmrs admin/Admin123
Some useful commands
Command | Description |
---|---|
docker-compose down | stop containers |
docker-compose rm -f | remove containers |
docker-compose up --force-recreate --remove-orphans --build | recreate containers when building |
docker volume ls | grep volume_name | list mounted volumes |
docker volume rm volume_name | delete volume |
docker volume rm composed_opensrp_couchdb_lucene \ | Delete all opensrp composed volumes |
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