之前在本地的时候,服务没有部在 docker 容器里,mysql 可以正常访问。 部署的时候将程序放在 docker 容器里,mysql 没放进去。导致线上 mysql 访问不了。 这个该怎么解决呢?
1
Trim21 2023-06-23 00:05:56 +08:00 via Android
|
2
oneisall8955 2023-06-23 00:41:27 +08:00 via Android
mysql 和服务的 docker 在同一台主机吗?同一台直接用 docker 的网卡+MySQL 的 IP 就行了,ifconfig 看下 docker0 网卡,如 172.17.0.1
|
3
BeautifulSoap 2023-06-23 00:45:11 +08:00 via Android
|
4
asvow 2023-06-23 10:10:31 +08:00 via iPhone
--link 参数 容器互联了解一下
|
5
asvow 2023-06-23 10:13:59 +08:00 via iPhone
以为 mysql 在另一个容器里🤦🏻♂️没仔细看题
|
6
hhjswf 2023-06-23 10:20:14 +08:00 via Android
好歹稍微学习一下再用吧
|
7
jack4536251 OP @hhjswf 官方有这个连接的文档吗?
|
8
mmdsun 2023-06-23 14:02:09 +08:00 via iPhone
--link 已经不推荐了,创建个网络然后用--network
|
9
LLaMA2 2023-06-23 14:32:50 +08:00
docker run -it alpine:3.16 ✔
/ # ls bin dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var / # ping baidu.com PING baidu.com (110.242.68.66): 56 data bytes 64 bytes from 110.242.68.66: seq=0 ttl=50 time=42.188 ms 64 bytes from 110.242.68.66: seq=1 ttl=50 time=40.774 ms ^C --- baidu.com ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 40.774/41.481/42.188 ms ### 192.168.124.23 是我的宿主主机的 IP / # ping 192.168.124.23 PING 192.168.124.23 (192.168.124.23): 56 data bytes 64 bytes from 192.168.124.23: seq=0 ttl=64 time=0.081 ms 64 bytes from 192.168.124.23: seq=1 ttl=64 time=0.149 ms ^C --- 192.168.124.23 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.081/0.115/0.149 ms / # ifconfig eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:02 inet addr:172.17.0.2 Bcast:172.17.255.255 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:55 errors:0 dropped:0 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:7615 (7.4 KiB) TX bytes:614 (614.0 B) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) / # mysql 在宿主机器有什么问题,完全没问题啊 |