java - Docker - Connect Apache Tomcat web server to MySQL server -
i trying connect web server runs in apache tomcat container mysql database runs container. in order using linking mechanism docker.
docker run -it --name ${container_name} --link db:db -p 8080:8080 -d tomcat
after running container can see containers linked , environment variables exposed properly.
in order connect web application running in tomcat container database, using following configuration file:
<context> <resource name="jdbc/mydb" type="javax.sql.datasource" auth="container" username="user" password="password" driverclassname="com.mysql.jdbc.driver" url="jdbc:mysql://${db_port_3306_tcp_addr}:${db_port_3306_tcp_port}/epcis?autoreconnect=true"> </resource> </context>
now problem can't establish connection database because environment variables exposed docker not recognized @ tomcat environment.
there way make these environment variables exposed docker visible apache tomcat environment?
could use dns declaration db , hard code reference? think /etc/hosts file updated db , it's ip address when --link it. could:
<context> <resource name="jdbc/mydb" type="javax.sql.datasource" auth="container" username="user" password="password" driverclassname="com.mysql.jdbc.driver" url="jdbc:mysql:db:3306/epcis?autoreconnect=true"> </resource> </context>
another technique use skydns , registrator, ip , port in dns srv record.
i don't remember tomcat should have access variables. sure tomcat evaluates url definition before using it?
Comments
Post a Comment