我在 tomcat 7 中成功部署了我的 war 文件并使用以下命令启动 tomcat
docker run -it --rm -p 7008:8080 -v //d/docker_tomcat/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml:ro -v //d/docker_tomcat/webapps:/usr/local/tomcat/webapps:rw tomcat:7.0
当tomcat启动时,它显示以下错误日志:-
使用了 AbandonedObjectPool (org.apache.commons.dbcp.AbandonedObjectPool@9030ca2)
已放弃日志:true
删除放弃:true
删除已放弃超时:90
[localhost-startStop-1] 错误 org.hibernate.util.JDBCExceptionReporter - 无法创建 PoolableConnectionFactory
我认为上述错误意味着数据库studentdb无法访问
这是我的 hibernate.properties 文件:-
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.username=root
hibernate.connection.password=root
hibernate.connection.url=jdbc:mysql://10.0.75.x<ip of docker>:3306/studentdb?autoreconnect=true&zeroDateTimeBehavior=convertToNull&jdbcCompliantTruncation=false
show_sql=false
hibernate.jdbc.use_streams_for_binary=false
hibernate.dbcp.testOnBorrow=true
hibernate.dbcp.validationQuery=SELECT 1 FROM DUAL
hibernate.dbcp.testOnReturn=false
hibernate.dbcp.maxWait=2000
hibernate.dbcp.testWhileIdle=true
hibernate.dbcp.minEvictableIdleTimeMillis=1800000
hibernate.dbcp.timeBetweenEvictionRunsMillis=300000
hibernate.dbcp.numTestsPerEvictionRun=5
hibernate.dbcp.removeAbandoned=true
hibernate.dbcp.removeAbandonedTimeout=90
hibernate.dbcp.logAbandoned=true
i think there may be error in hibernate.connection.url property of hibernate.properties file.
还有疑问是因为我的 Windows 10 使用 mysql 端口 3306,而 docker 也使用 mysql 端口 3306。如果是问题那么我如何使用不同的端口更改在 docker 中运行的 mysql 容器的端口
最佳答案
使用以下命令将本地端口转发到 docker 容器端口
docker run -p <LOCAL-PORT>:3306 <mysql-image-name>
关于mysql - 是否可以在 docker mysql 运行容器以及 windows 10 mysql 中使用 3306 端口(相同端口),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46112858/