我有一个带有Spring Boot应用程序的Docker容器。我希望该容器可以连接到VPN,并且可以从外部进行访问。我执行openvpn
命令,连接到VPN,但是然后我无法访问我的spring boot应用程序。容器已连接到两个内部网络,当我写route -n
时,显示下一个(没有vpn):
root@a2f6de2387b9:/# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.18.0.1 0.0.0.0 UG 0 0 0 eth0
172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
172.22.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1
当我连接到VPN时:
root@a2f6de2387b9:/# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.8.1.1 128.0.0.0 UG 0 0 0 tun0
0.0.0.0 172.18.0.1 0.0.0.0 UG 0 0 0 eth0
10.8.1.0 0.0.0.0 255.255.255.0 U 0 0 0 tun0
89.X.X.X 172.18.0.1 255.255.255.255 UGH 0 0 0 eth0
128.0.0.0 10.8.1.1 128.0.0.0 UG 0 0 0 tun0
172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
172.22.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1
如何配置容器以从外部访问?
谢谢。
编辑:
借助这篇文章,我设法从Internet访问了该容器:https://serverfault.com/questions/659955/allowing-ssh-on-a-server-with-an-active-openvpn-client
但是现在我有另一个问题,我没有连接到另一个容器。我的码头工人有两个网络:--network net-mynet1
和--network net-mynet2
。当我ping mysql-db2
(位于net net-mynet2 中)时,它可以正常工作,但是如果我ping mysql-db1
(位于net net-mynet1 中,则它正常工作) ),它什么也没做。