Running Bahmni on Docker (Archived)
Note, this instruction does not work with CentOS 7.x. This is applicable for Bahmni 0.91 on CentoS 6.9+
ARCHIVED PAGE!
This is an ARCHIVED PAGE and available for historial reference only. For LATEST documentation on Bahmni supported docker setup please refer this page instead: Running Bahmni on Docker.
Docker installations
You can install Docker community edition from here. Choose the appropriate installers for your host machine and follow the instructions mentioned for the host platform.
MacOS: You can get the dmg file for Docker here.
Once you have Docker installed, ensure that you are running the daemon. If you want to tune and configure docker, please find detailed information here
While it is not mandatory that you have working knowledge of docker (although desirable), at the least you should know the following commands and usages
- "docker ps -a" - shows all containers
- "docker rm <container id>" - remove a given container
- "docker container COMMAND" - different commands like start/stop/prune for container(s)
- "docker images" - lists all images
- "docker rmi <image id>" - remove a given image
"docker volume COMMAND" - different commands for managing volumes.
Bahmni Docker Setup Process
Step 1: Create a directory (e.g. dev_dockerFiles) and get the following files and put them in the directory.
- Dockerfile - is a document that contains all the commands to assemble an image, and a way to create an automated build that executes several command-line instructions.
- docker.sh - an utility script to do some basic cleanups and checks and run the docker build and run command.
- db_startup_script.sh - an utility script to setup databases and setup the database configurations and data directories and to restart the services. This also runs every time you start the container.
Make sure the docker.sh file is executable:
chmod a+x docker.sh
Also, this link has more advanced scripts for cloud hosting, which you will obviously need to enhance for your specific security or SSL certificate installations, but should give you enough pointers on how to use on actual production.
Dev:Shared Directory from host
If you are spinning up for development purpose, chances are that you want to share files or other artefacts between the host and the container. The simplest way to do this, is to share a directory from the host machine as a volume in the container. To do this, edit the docker.sh file, and modify the last line of "docker run ..."
docker run -e container_name=${container_name} -it -d -p ${https_port}:443 -p ${http_port}:80 -p ${erp_port}:8069 -p ${debug_port}:8000 --privileged --name $container_name -v /<bahmni root directory on your host machine>:/bahmni_host -v $container_name:/$container_name bahmni/bahmni_centos67 /bin/bash
notice the additional volume specified after the "–name $container_name"? Within the container "/bahmni_host" will now be the shared folder with your host machine.
-v /<bahmni root directory on your host machine>:/bahmni_host
Step 2: In "docker.sh", check and specify version of Bahmni you want to install, what ports to bind and container name that you want to have etc.
Container name: default container914
export container_name=container914
(I like to name the containers by the version of Bahmni I am installing. Notice the name?)
- Bahmni Version: change the "rpm_version" variable.
export rpm_version=0.91-4
You can mention a specific version (like above), or the latest (like below)
export rpm_version=0.91*
The above is applicable if you are installing the development versions. You will want to have a fixed version for production! The binaries get downloaded from S3 repo, which is mainly used for development/QA purposes, change the repo to bintray in the Dockerfile.
Ports: These are the ports that will be bound from your host to the docker container.
export https_port=443 export http_port=80 export erp_port=8069 export debug_port=8000
Inventory: Specifies what components you want installed. The inventory file controls what components of Bahmni gets installed. For example, if you want PACs (dcm4Chee) to be installed, then you should update the inventory file so that "dcm4chee" and "dcm4chee-db" have the location specified, which in this case would just be 127.0.0.1. In this example, the inventory name is set as "aws_qa03" in the docker.sh file.
export inventory_name=aws_qa03
The inventory file gets downloaded from bahmni-tw-playbooks repo. Note, these are sample inventory files. If you want to have your own inventory file, just download one of the inventory files and modify it appropriately locally, and then specify your local file to be used. To do that follow the steps below (assuming you have your local inventory as "local")
a) comment off the below line in "Dockerfile"
# RUN wget -O /etc/bahmni-installer/local https://raw.githubusercontent.com/Bahmni/bahmni-tw-playbooks/master/inventories/$inventory_name
b) And add the following line
ADD local /etc/bahmni-installer/local
Step 3: Run the following command from the directory you created above ("dev_dockerFiles")
$ cd dev_dockerFiles $ sudo ./docker.sh
Step 4: If all goes alright, your docker container is all set, and you can login to the container
$ docker exec -i -t <container_name> /bin/bash
Step 5: Check if Bahmni is running by opening a browser and typing the URL "https://localhost" or "https://localhost/bahmni/home". Also login to the container and see if the servers are running (if you get a message on the browser like 'System down for maintenance').
$ docker exec -i -t <container_name> /bin/bash $ curl http://localhost $ service openmrs status $ service httpd status $ service mysqld status $ service postgresql-9.2 status
And assuming all went well, congratulations, you are all set with dockerized bahmni!
Step 6: Ok, now that everything is up, its a good idea to commit all your changes to the container locally. To do this, follow the suggestion below
$ docker commit <container_name> bahmni/bahmni_centos67:version91401012018 # I like to tag with the version & date that I installed.
You can then stop/start the container. You can also pause, unpause container to reduce overload on your system
Troubleshooting
Like everything else, things do not go quite alright every time. Following are some of the hiccups we have faced and here are some pointers for resolutions
- Running the docker.sh script failed.
- Please check the log on the console. Try to find out what went wrong. Ask for help in community channels (slack or OpenMRS talk)
- Try running the script again. Sometimes internet is just flaky, and download of some packages might have failed. Try to go through the console log and see if some warning or error were logged before the eventual step of exit.
- Try to delete the old docker containers and images and re-run the script.
- Try removing the volume.
- Read the fine manual(s) - docker, bahmni etc! Google - chances are someone already came across the same problem.
- Running the docker.sh script went fine, essential openmrs and other application services are running, but databases seemed not running. Try starting the databases manually. NOTE: do these inside the container, not in your host machine.
- if you get messages like "Mysql is dead but subsys locked", try deleting the mysql lock file from "/var/lock/subsys/"
- If you get messages like "Lock file 'postmaster.pid' file already exists, try deleting pid file from '/usr/local/var/postgres'.
Check ownership of the mysql data directories. Change to 'mysql' if not
$ sudo chown -R mysql:mysql /var/lib/mysql
If the databases are not running, try running the startup script within the container
$ cd /tmp $ ./db_startup_script.sh
- In few occasions (noticed on OSX Sierra), the mysql database is found to be corrupted post installation. To resolve this, do the following
stop mysql => setup innodb force recovery in my.cnf => start mysql => stop mysql > change my.cnf to comment off the innodb recovery line => start mysql => start application services.
$ service mysqld stop $ vi /etc/my.cnf # add innodb_force_recovery=1 towards the end, save the file $ service mysqld start # it should go through the restoration process $ service mysqld stop $ vi /etc/my.cnf # comment off the innodb_force_recovery line $ service mysqld start $ service openmrs start $ service bahmni-reports start
The database didn't get installed at all. Few have faced this on Mac and Ubuntu. To check this go to /{container_name}/mysql/ and see if there exists a database "openmrs". If not, then the database didn't get copied for some reason. To fix this, do as described below
$ service openmrs stop $ service bahmni-reports stop $ service mysqld stop $ rsync -avr -o -g /var/lib/mysql /${container_name} # ${container_name) is the name you have given to your container. $ ls -al /${container_name}/mysql/ # verify that 'openmrs' directory exists $ service mysqld start $ service openmrs start $ service bahmni-reports start
Its always a good idea to save your container (using docker commit command) above once you have resolved any issues.
Please leave a comment if you find any issues and resolutions. Better still, start a thread on OpenMRS talk channel on Bahmni, or communicate over slack or IRC.
Developer Notes
Assuming that you, as a developer, have set up your docker instance like above and verified applications are running, you probably want to use docker as your developer environment while your primary development (writing code) happens in the host.
Remember that you have mapped your bahmni working above following instructions at this step 1 info? Within the container, "/bahmni_host/" is now the shared directory for your codes checked our in the host bahmni working directory.
Prepare your development machine as described Setting up Bahmni Dev Environment
- Working on Bahmni Apps
Just like it is described in Setting up Bahmni Dev Environment#CreateLinkstoyourHostMachineFoldersforEMRUI, you want to link up your code from development machine to the running environment in Docker, only difference been the reference-able directory from docker is now "/bahmni_host/". For example, if you want "/var/www/bahmniapps" to point to your code, then create a symlink like
$ sudo ln -s /bahmni_host/openmrs-module-bahmniapps/ui/app /var/www/bahmniapps
- Working on "App Config"
- If you want to map your working app configurations then create a symlink like
$ ln -s /bahmni_host/default-config /var/www/bahmni_config
- If you want to map your working app configurations then create a symlink like
- Developing OpenMRS Modules refer to Setting up Bahmni Dev Environment#DevelopingOpenMRSJavamodules
- Debugging Java Processes: It is same as described here, other than that the IP address is different
- remember you mapped ports in Step 2.4?
- (Q: Did you remember to save your container with a local commit?)
The Bahmni documentation is licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)