我跑了码头工人的容器一个是Tomcat和一个phpMyAdmin的。 我跑这个命令phpMyAdmin的容器:
docker run -d -p 49160:22 -p 49161:80 -p 49162:3306 --name db phpmyadmin:imported
我可以看到我的浏览器上的端口49161.我用这个命令运行Tomcat容器phpMyAdmin的
docker run -it -v ~/docker/tomcat/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml --name tomcat --link db:server -p 8888:8080 tomcat:deployed
每一件事情看起来不错。 我可以ping从Tomcat容器的分贝。 但是当我尝试连接到它使用Hibernate和我的J2EE应用程序我碰到下面的错误。
10-Jun-2015 19:20:12.293 WARNING [http-nio-8080-exec-15] org.hibernate.cfg.SettingsFactory.buildSettings Could not obtain connection metadata
java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:690)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:56)
这是我的hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://172.17.0.20:3306/auction</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<mapping class="ie.domain.entity.User"/>
<mapping class="ie.domain.entity.Auction"/>
<mapping class="ie.domain.entity.Offer"/>
</session-factory>
</hibernate-configuration>
我尝试使用名称服务器,而不是IP,也我想,而不是3306端口49162,我得到了同样的错误。