Use docker with external database

Dear all,

I used the openmrs-sdk to generate the docker-compose file : mvn openmrs-sdk:build-distro which is working fine. However, in my case I have to use an external database server. So I modified, like mentioned in the wiki , in the .yml file by removing the db service part and setting up my external database as mentioned here . here is my yml file : # Generated automatically by openmrs SDK version: ‘2’

services:
  web:
    build: web
    image: referenceapplication:1.0.0-snapshot
    environment:
      DB_DATABASE: openmrsdocker
      DB_HOST: my_ip_address
      DB_USERNAME: my_dv_user
      DB_PASSWORD: my_db_password
      DB_CREATE_TABLES: 'true'  # change to 'true' if using an empty database
      DB_AUTO_UPDATE: 'true'    # change to 'true' if using an empty database
      MODULE_WEB_ADMIN: 'true'   # allow web admin on OpenMRS
    volumes:
      - web-data:/usr/local/tomcat/.OpenMRS
      - /usr/local/tomcat/.OpenMRS/modules/ # used to mount persistent docker volume for modules
      - /usr/local/tomcat/.OpenMRS/owa/     # used to mount persistent docker volume for owa

volumes:
  web-data:

But it doesn’t work. And I had two different behaviors depending on my database server location: When I refer to my local database in the same machine with my docker. It looks like the connection is ok but I have this error message :

 2019-03-08 08:18:57,879| Got exception while starting up:
web_1  | java.lang.RuntimeException: Error occurred while trying to get the updates needed for the database. Unable to get a connection to the database.  Please check your openmrs runtime properties file and make sure you have the correct connection.username and connection.password set
web_1  |        at org.openmrs.util.DatabaseUpdater.getUnrunDatabaseChanges(DatabaseUpdater.java:628)
web_1  |        at org.openmrs.util.DatabaseUpdater.getUnrunDatabaseChanges(DatabaseUpdater.java:584)
web_1  |        at org.openmrs.util.DatabaseUpdater.updatesRequired(DatabaseUpdater.java:249)
web_1  |        at org.openmrs.web.Listener.setupNeeded(Listener.java:222)

And when I refer to an external server. The process stopped earlier with timeout error:

web_1  | owa.openmrs-owa-sysadmin=1.2
web_1  | version=1.0.0-SNAPSHOT
web_1  | war.openmrs=2.1.4
web_1  | -----------------------------------
web_1  | + echo -----------------------------------
web_1  | + /usr/local/tomcat/wait-for-it.sh --timeout=3600 xxxxxxxx:3306
web_1  | wait-for-it.sh: waiting 3600 seconds for xxxxxxxx:3306
web_1  | wait-for-it.sh: timeout occurred after waiting 3600 seconds for xxxxxxxx:3306

Do you have any feedback on that ? @mksd @lilian

Thanks a lot in advance Regards

1 In the “local case”, are you 100% sure that there exists a MySQL user whose credentials match what’s in the openmrs-runtime.properties file:

connection.username=...
connection.password=...

2 In the “remote case” I would look at what this wait-for-it.sh script does and I would try to make it work in isolation of the whole shebbang here. What’s in that script?

Thanks for your feedback,

  1. The username / password are filled in the .yml file :
  environment:
      DB_DATABASE: openmrsdocker
      DB_HOST: my_ip_address
      DB_USERNAME: my_dv_user
      DB_PASSWORD: my_db_password

and yes the database exist, the only thing is that I am using a root user, but I don’t think it changes anything.

  1. That script is used to test the hostname connection.

Thanks and regards

1 Can you simply do?

mysql -u my_dv_user -p my_db_password openmrsdocker

If that’s successful then everything should be fine.

2 Can you run that script in isolation of the whole SDK/Docker context, just to verify that you can get it working with your remote database?

  1. looks ok:

C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -u root -p openmrsdocker Enter password: ***** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 20 Server version: 5.6.39-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>

  1. I will try and keep you informed

1 So in the .yml file you need to provide root’s credentials right, something like:

environment:
  DB_DATABASE: openmrsdocker
  DB_HOST: localhost
  DB_USERNAME: root
  DB_PASSWORD: [root_password_here]
  1. Yes , that’s what I did. in fact, I used the ip address instead of localhost.

So are you ok with 1?

  1. No it still not work. What Isaid is that we should not put localhost because it refers to docker image itself. But even with the ip address, I got the error message above (username password error).

Once the Tomcat container is running, you should go within and troubleshoot from within how to access this external MySQL server/database. I don’t know if the original error message is accurate (as it pushes you to check the user’s credentials) or if in fact it’s just a problem of routing.

What IP address did you provide then, I guess it should be the Docker host URL?