How to use MySQL in docker enviroment?

I want to use MySQL,but it still cause error about couldn’t load driver class com.mysql.jdbc.Driver
How can I upload mysql driver to docker container?

Hi.
Because of license constraints we can’t distribute docker images with the MySQL connectors included.
There are 2 options here;

  1. configure the existing runtime properties of the images
    this would f.e. include changing the JDBC connection string. But also modifying the classpath of the executable WAR by changing the Docker RUN command (for adding the connector.jar).

  2. build your own version of the needed image(s)

For now I would go for option 2.
Take a look at the /docker folder for scripts to build the Docker images plus example Docker Compose configurations.
Also look at the related pom.xml files and especially the ‘docker’ profile section.

We will try to make things easier regarding this aspect in coming releases. But like I mentioned before. We can’t distribute them. But we can try to make it easier to configure it.

Regards,

Yvo

Hi @yvo is there a way to do this ?
I also want to use docker flowable connecting to a custom mysql host.

Hi.

When going for option 2; create a new image that will contain the mysql driver jar; you can do something like this.

  1. create the Dockerfile for the custom image.
FROM flowable/flowable-ui:6.7.2

ADD mysql-connector-x.jar /app/WEB-INF/lib/
  1. build the custom image
docker build -t flowable-ui-mysql .
  1. run a container providing the database connection configuration
docker run --rm --name flowable-mysql \
-e spring.datasource.url="jdbc:mysql://<db_host>:3306/<db_name?characterEncoding=UTF-8" \
-e spring.datasource.username=<db_username> \
-e spring.datasource.password=<db_password> \
flowable-ui-mysql

Hope this helps.

Kind regards,

Yvo

I am getting the following exception.
I have verified that mysql is running on port 3306 and credentials are correct in my local

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

  •    at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-j-8.0.31.jar:8.0.31]*
    
  •    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-j-8.0.31.jar:8.0.31]*
    
  •    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828) ~[mysql-connector-j-8.0.31.jar:8.0.31]*
    
  •    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448) ~[mysql-connector-j-8.0.31.jar:8.0.31]*
    
  •    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241) ~[mysql-c*
    

How are you starting the container?

This is how i am running it

docker run --rm --name flowable-mysql -p 8082:8080 \
-e spring.datasource.url="jdbc:mysql://127.0.0.1:3306/flowabletest?characterEncoding=UTF-8" \
-e spring.datasource.username=mydbusername \
-e spring.datasource.password=mydbpassword \
flowable-ui-mysql

You are making the container connect to the mysql host running on 127.0.0.1.
That does not seem correct. Because that would most probably be the container itself.
You need to provide the ip / hostname where the database is running.

Tip: if the mysql server is running on the host system you can use host.docker.internal as the hostname. This wil resolve to the docker host ip.

The issue is resolved, thanks, this is the final command I used in my mac to run it

docker run --rm --name flowable-mysql -p 8082:8080 \
-e spring.datasource.url="jdbc:mysql://docker.for.mac.host.internal:3306/flowabletest?characterEncoding=UTF-8" \
-e spring.datasource.username=mydbusername \
-e spring.datasource.password=mydbpassword \
flowable-ui-mysql

Thanks a lot @yvo

:+1:

Thanks for the feedback.