Setting up using SDK with Docker MySQL on MacOS

I’ve been trying to set up an SDK server on a mac, using dockerized MySQL. At first when I ran the SDK setup command it would give me an error like “Failed to connect”.

Starting 'openmrs-sdk-mysql-v8-4-1' DB docker container...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  52.660 s
[INFO] Finished at: 2025-11-14T23:54:02-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.openmrs.maven.plugins:openmrs-sdk-maven-plugin:6.7.0:setup (default-cli) on project standalone-pom: Failed to setup server: Failed to connect to the specified database jdbc:mysql://localhost:3308/refapp?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&sessionVariables=default_storage_engine%3DInnoDB: Communications link failure

The docker container for MySQL appears to have been created, and is shown as running in Docker Desktop, but has no port binding. Since it has no port binding, nothing can connect to it.

I didn’t realize that that was the problem at first, so I ran setup -DdockerHost=host.docker.internal (I got mixed up—“host.docker.internal” is how the container would access the host machine, the real problem is the lack of a port binding). Unfortunately this seems to have broken my SDK somehow. It gave me the error

Preparing 'openmrs-sdk-mysql-v8-4-1' DB docker container...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:11 min
[INFO] Finished at: 2025-11-15T00:11:04-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.openmrs.maven.plugins:openmrs-sdk-maven-plugin:6.7.0:setup (default-cli) on project standalone-pom: Failed to setup server: Unable to execute mojo: Execution null of goal org.openmrs.maven.plugins:openmrs-sdk-docker-maven-plugin:6.7.0:create-mysql failed: Cannot invoke "String.hashCode()" because "<local2>" is null -> [Help 1]

Now, every subsequent attempt to do SDK setup results in the same error on the database setup step, regardless of whether I include the dockerHost flag or not.

Help or advice would be greatly appreciated.

Ok I fixed the persistent “Cannot invoke “String.hashCode()” because “” is null” failure by deleting the line from sdk.properties where the dockerHost argument had been saved.

How can I get the SDK to create a mysql container with the port binding? CC @cioan @dkigen I think I remember you guys using macs…

I have just run the sdk and the mysql docker container has the expected port binding according to this line: openmrs-sdk/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DefaultWizard.java at 6.7.0 · openmrs/openmrs-sdk · GitHub

FWIW, for the database step, i chose 2) MySQL 8.4.1 and above in SDK docker container (requires pre-installed Docker)

Detailed log for the database part can be found at: Which database would you like to use?:1) MySQL 5.6 and above (requires pre-ins - Pastebin.com

I am running Docker Desktop version 4.15.0 (93002)

And this is my value in the sdk.properties file: dockerHost=unix:///var/run/docker.sock

Can you try to run the sdk setup command again after deleting the container, image, and your sqk.properties file?

Interesting. I have removed sdk.properties and deleted the MySQL docker container and image and re-run SDK setup. I am choosing the same database option as you. Here is the log from that point:

Which database would you like to use?:
1) MySQL 5.6 and above (requires pre-installed MySQL 5.6 and above)
2) MySQL 8.4.1 and above in SDK docker container (requires pre-installed Docker)
3) Existing docker container (requires pre-installed Docker)
4) PostgreSQL 8.2 and above

Which one do you choose? [1/2/3/4]: 2

-DdockerHost is not specified in batch mode. Attempting to find default docker host address...

Checking "Docker Toolbox"

Running `docker-machine url` to determine the docker host...

Failed checking "Docker Toolbox"

Trying default UNIX socket as docker host address...

Preparing 'openmrs-sdk-mysql-v8-4-1' DB docker container...
[INFO]
Started downloading mysql:8.4.1 image ...
[INFO]
Finished!

Starting 'openmrs-sdk-mysql-v8-4-1' DB docker container...
[INFO]
Trying to connect to the DB...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  02:01 min
[INFO] Finished at: 2025-11-16T19:25:44-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.openmrs.maven.plugins:openmrs-sdk-maven-plugin:6.7.0:setup (default-cli) on project standalone-pom: Failed to setup server: Failed to connect to the DB in the 'openmrs-sdk-mysql-v8-4-1' container at 'jdbc:mysql://localhost:3308' -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Same as yours, it set dockerHost in sdk.properties:

dockerHost=unix\:///var/run/docker.sock

But in my case, the container does not have the port bound:

~/openmrs $ docker ps
CONTAINER ID   IMAGE         COMMAND                  CREATED         STATUS         PORTS      NAMES
970abffafff0   mysql:8.4.1   "docker-entrypoint.s…"   5 minutes ago   Up 5 minutes   3306/tcp   openmrs-sdk-mysql-v8-4-1

Looking at the host logs, it looks like the port gets bound and immediately unbound:

docker-monitor.log.txt (85.4 KB)

I can start a container with the correct port binding from the command line:

~/openmrs [1] $ docker run -d \
                      --name openmrs-sdk-mysql-v8-4-1 \
                      -e MYSQL_ROOT_PASSWORD=Admin123 \
                      -e MYSQL_USER=openmrs \
                      -e MYSQL_PASSWORD=Admin123 \
                      -p 3308:3306 \
                      mysql:8.4.1 \
                      --character-set-server=utf8 \
                      --collation-server=utf8_unicode_ci
11424a659baf662eb3119c5ca31b779f31beddfe17fd8c4fcbfd0417b2383476
~/openmrs $ docker ps
CONTAINER ID   IMAGE         COMMAND                  CREATED         STATUS         PORTS                                         NAMES
11424a659baf   mysql:8.4.1   "docker-entrypoint.s…"   4 seconds ago   Up 3 seconds   0.0.0.0:3308->3306/tcp, [::]:3308->3306/tcp   openmrs-sdk-mysql-v8-4-1

I’ve now got a server set up using “3) Use a running Docker container.” Hopefully others don’t run into this issue—maybe a transient Docker Desktop bug or something.

Docker Desktop version 4.51.0 (210443), on Engine 28.5.2, compose 2.40.3-desktop.1.

I came across the same issue and had to do the same thing as you to get it working, i.e. start a container with the port binding from the command line and then use a running docker container

1 Like

Very interesting! Thanks for this feedback. :+1: