Docker is a software containerization platform.
Docker containers wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries – anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment.
This is useful when running OpenSRP server because it requires mysql, couchdb, couchdb-lucene, activemq and openmrs services to be installed.
Before going through this setup, checkout the links below to install docker:
Steps for setting up OpenSRP docker container
- Checkout opensrp-server and compile opensrp war file i.e. OpenSRP Server Build step 6.
- Change MySQL and CouchDB database credentials in opensrp.properties file
- Change MySQL credentials in quartz.properties
- Change ActiveMQ configuration in activemq.properties if applicable
- Checkout opensrp docker builds and navigate to the root folder.
Create a webapps folder and copy the compiled war file to the new directory.
mkdir webapps cp <opensrp-server>/opensrp-web/target/*.war webapps
Build the container
docker build -t onaio/opensrp .
Run the container
docker run -d --name='opensrp' -e MYSQL_ROOT_PASSWORD='mypassword' -e MYSQL_MOTECH_DATABASE='motechquartz' \ -e MYSQL_OPENMRS_USER='openmrs' -e MYSQL_OPENMRS_PASSWORD='openmrs' -e MYSQL_OPENMRS_DATABASE='openmrs' \ -e COUCHDB_USER='rootuser' -e COUCHDB_PASSWORD='adminpass' \ -p 3306:3306 -p 5984:5984 -p 5985:5985 -p 8161:8161 -p 61616:61616 -p 9090:8080 onaio/opensrp
The docker run command given starts a container named 'opensrp' with the following variables and ports
Variables https://docs.docker.com/engine/reference/run/#/env-environment-variables
ENV Description MYSQL_ROOT_PASSWORD
password for mysql root user
MYSQL_MOTECH_DATABASE
motech database name
MYSQL_OPENMRS_USER
openmrs database user name
MYSQL_OPENMRS_PASSWORD
openmrs database password
MYSQL_OPENMRS_DATABASE
openmrs database name
COUCHDB_USER
couchdb root/system user name [Optional]
COUCHDB_PASSWORD
couchdb root/system password [Optional]
Ports https://docs.docker.com/engine/reference/run/#/expose-incoming-ports
Service Host Port Container Port mysql 3306 3306 couchdb 5984 5984 couchdb-lucene 5985 5985 activemq 8161 8161 activemq 61616 61616 tomcat7 9090 8080 NB: Host ports can be changed i.e. if mysql is already installed in port 3306, host port 3306 can be changed to 3307.
Check the logs
docker logs -f opensrp
-f option follows log output.
No errors/exceptions should be displayed in the logs if the container has started successfully.
Copy opensrp war to the container's webapps folder
docker cp webapps/opensrp.war opensrp:/opt/tomcat/webapps
Test the services
Service Link Credentials OpenSRP http://localhost:9090/opensrp OpenMRS http://localhost:9090/openmrs admin/Admin123 CouchDB http://localhost:5984 rootuser/adminpass CouchDB Lucene http://localhost:5984 ActiveMQ http://localhost:8161 MySQL http://localhost:3306 root/mypassword
Some useful commands
Command | Description |
---|---|
docker stop opensrp | Stops opensrp container |
docker rm opensrp | Removes opensrp container |
docker rmi onaio/opensrp | Removes onaio/opensrp image |
docker exec -it opensrp bash | Go to opensrp container |
docker ps -a (-a shows all containers) | List containers |
docker images | List images |
Checkout Docker Compose Setup for an advanced docker setup.
Checkout Cloudant Sync Security Configuration especially step 8 for information on how to link lucene with a secure CouchDB. This can be helpful when COUCHDB_USER and COUCHDB_PASSWORD variables have been set.
References
https://hub.docker.com/_/mysql/
https://hub.docker.com/_/couchdb/
https://github.com/klaemo/docker-couchdb-lucene
https://hub.docker.com/r/rmohr/activemq/