docker 从 tomcat 容器连接到 mysql 容器
1.查看mysql容器的ip
打包成war文件之前,一定要把Java web项目里jabc.properties里面的连接mysql的配置更改一下,改成docker里的mysql容器的ip地址,(如database.url=jdbc:mysql://172.17.0.3:3306/traceability?useUnicode=true&characterEncoding=utf-8)如果用到了mybatis,也要把配置文件修改 一下,查看mysql容器的ip地址,可以用命令docker insepect mysql(容器名称)进行查看。
我们可以通过以下命令查看容器运行的各种数据
docker inspect mycentos2
也可以直接执行下面的命令直接输出IP地址
docker inspect --format='{{.NetworkSettings.IPAddress}}' mycentos2
---------------------
作者:simpledoo
来源:CSDN
原文:https://blog.csdn.net/liqz666/article/details/82253486
版权声明:本文为博主原创文章,转载请附上博文链接!
"Ports": {
"3306/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "3306"
}
],
"33060/tcp": null
},
"SandboxKey": "/var/run/docker/netns/5c0037e88199",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "46c2952c3f43370b3478bc45fb0c2cb4cfef12342542fcbe44bb2269d7fc83e4",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:03",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "6e2ba28ae4226a6b07e6f18f3169e4f38822d06a0d40d33e7231b4f8f4d82375",
"EndpointID": "46c2952c3f43370b3478bc45fb0c2cb4cfef12342542fcbe44bb2269d7fc83e4",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.3",//mysql容器的ip
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:03"
}
3.解释:这里各个容器中通过ip去互通