I am totally new to Docker. Now I have this Spring MVC app (running on wildfly) which uses a MySQL DB which i want to Dockerize. I did create a Docker file whose contents are below
FROM jboss/wildfly
# ADD nummerreeks.war /opt/jboss/wildfly/standalone/deployments/
ADD test.war /home/Docker/app
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
And a docker-compose file which is below :
version: '2'
services:
database:
image: mysql:latest
ports:
- 3306
environment:
MYSQL_ROOT_PASSWORD: admin
MYSQL_USER: test
MYSQL_PASSWORD: admin
MYSQL_DATABASE: dbpass
wildfly:
image: bitnami/wildfly:latest
ports:
- '8080:8080'
- '9990:9990'
links:
- app
volumes_from:
- app
app:
image: test/demo
volumes:
- wars:/opt/jboss/wildfly/standalone/deployments/
links:
- database
volumes:
wars:
driver: local
Now when run this using :
docker run -t -p 8080:8080 --name dockerapp test
I get this DB exception,
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:289)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:447)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:277)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy56.listRequesterData(Unknown Source)
at nl.naturalis.nrs.controller.NummerreeksController.getRequesterList(NummerreeksController.java:547)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
I believe its reading the db config from the DB connection values from the DB.config file in the application instead of the docker-compose file.
Anyone with any pointers to what am i doing wrong here?