我对docker完全陌生。现在我有了这个springmvc应用程序(在wildfly上运行),它使用了一个mysql数据库,我想对它进行dockerize。我确实创建了一个docker文件,其内容如下
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
以及docker compose文件,如下所示:
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
现在使用以下命令运行时:
docker run -t -p 8080:8080 --name dockerapp test
我有个db例外,
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)
我相信它是从应用程序中db.config文件的db connection值读取db config,而不是从docker compose文件读取。
有人指出我做错了什么吗?
暂无答案!
目前还没有任何答案,快来回答吧!