Reputation: 1812
I have mysql server running in centos host and I want to deploy my war in tomcat inside docker container in same host. Any idea how can I connect mysql from inside the container.
Upvotes: 6
Views: 6927
Reputation: 10917
Here is what you can do to connect to the DB (mysql) from the App (tomcat). There are two ways you can do this
Example-1 (Links)
"docker run --name db -e MYSQL_ROOT_PASSWORD="xxxx" -e MYSQL_DATABASE="xxxx" -d mysql"
docker run -d -p 8080:8080 --name app --link db:db -v $PWD/webapp:/var/lib/tomcat7/webapps/ app
Example 2:
If you want to use Host's mysql
docker run -d --net=host --name app image command
Do let me know if you need any further explanation. You can go through the topics on volumes, links from docker documentation: https://docs.docker.com/
Upvotes: 9