Error Setting up OpenMRS Using Mysql Docker Container

I was trying to reproduce the error in this thread. Unfortunately I ran into something else which I don’t know how to solve.

I cloned the master of openmrs-core and run the following commands.

$ git pull upstream master
$ mvn clean install
$ cd webapp && mvn jetty:run

Everything works as expected after which I opened the URL http://localhost:8080/openmrs in the browser where I am presented with the initial setup page. Below are screen shorts showing stage by stage setup information I entered in each step.

The next step creates the database successfully, however when the new user is created the subsequent connection to the database fails. (See the error log below)

WARN - InitializationFilter.verifyConnection(999) |2017-04-06 11:18:32,205| Error while checking the connection user account
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	at com.mysql.jdbc.Util.getInstance(Util.java:386)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
	at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2395)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2316)
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:347)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:247)
	at org.openmrs.web.filter.initialization.InitializationFilter.verifyConnection(InitializationFilter.java:990)
	at org.openmrs.web.filter.initialization.InitializationFilter.access$300(InitializationFilter.java:83)
	at org.openmrs.web.filter.initialization.InitializationFilter$InitializationCompletion$1.run(InitializationFilter.java:1483)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLException: Access denied for user 'test_user'@'172.17.0.1' (using password: YES)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1086)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:928)
	at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1750)
	at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1290)
	at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2493)
	at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2334)
	... 16 more

On examining the error below it appears that the system is attempting to connect an IP (172.17.0.1) which is different from the one I provided in the JDBC connection string during configuration. I don’t know why this happens but obviously it is the reason for the connection failure.

Specification Java 1.8.0_111 Openmrs version 2.2.0-97c176 Using MySQL running in docker container exposed via port 37269.

It will be nice to figure out why and how the database IP is somehow changed.

Note I may not be responding to this thread readily because I posted this merely to bring attention to anyone who could be interested.

Looks like you have 127.0.0.1 on your second screenshot.

That IP looks like it’s on the Docker network. For completeness, can you also post the command you used to run the MySQL container and the output of docker ps?

EDIT: Is the port 32769 or 37269?

@willa Shouldn’t you be using docker containers IP address?

You could try running docker with --net flag set to host to access the host machine using localhost

docker run --net=host <>