如何启用Docker容器的出站连接?

我有一个托pipe在Docker cloudASP.NET Core应用程序(云提供程序是Azure )。 应用程序使用Hangfire在后台运行循环作业,其中一个作业需要从外部REST API请求数据。 我注意到任何出站通信的尝试都失败了,我想知道如何启用它。

该部署由一些其他容器组成,因此链接的容器(服务)可以毫无问题地进行通信。 没有专门的networkingconfiguration; 使用默认的“桥”模式。 我是否需要在容器的映像中configuration某些内容,或者是否需要更改networking设置…我不知道。

没有专门的networkingconfiguration; 使用默认的“桥”模式。

根据你的描述,似乎你正在使用虚拟机并运行docker。 如果你想从互联网上访问这个docker,我们应该将docker端口映射到本地端口,例如:

 docker run -d -p 80:80 my_image service nginx start 

在将端口80映射到此VM之后,我们应该将入站规则添加到Azure networking安全组 (NSG),我们可以按照本文进行添加。

另外,我们应该添加端口80到OS filewall入站规则。


更新

对不起,误会了。

这里是我的testing,我在Azure VM(Ubuntu 16)上安装docker,然后创build一个centos docker,像这样:

 root@jasonvms:~# docker run -i -t centos bash Unable to find image 'centos:latest' locally latest: Pulling from library/centos d9aaf4d82f24: Pull complete Digest: sha256:4565fe2dd7f4770e825d4bd9c761a81b26e49cc9e3c9631c58cfc3188be9505a Status: Downloaded newer image for centos:latest [root@75f92bf5b499 /]# ping www.google.com PING www.google.com (172.217.3.100) 56(84) bytes of data. 64 bytes from lga34s18-in-f4.1e100.net (172.217.3.100): icmp_seq=1 ttl=47 time=7.93 ms 64 bytes from lga34s18-in-f4.1e100.net (172.217.3.100): icmp_seq=2 ttl=47 time=8.13 ms 64 bytes from lga34s18-in-f4.1e100.net (172.217.3.100): icmp_seq=3 ttl=47 time=8.15 ms ^C --- www.google.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2001ms rtt min/avg/max/mdev = 7.939/8.076/8.153/0.121 ms [root@75f92bf5b499 /]# ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=51 time=1.88 ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=51 time=1.89 ms 64 bytes from 8.8.8.8: icmp_seq=3 ttl=51 time=1.86 ms c64 bytes from 8.8.8.8: icmp_seq=4 ttl=51 time=1.87 ms 64 bytes from 8.8.8.8: icmp_seq=5 ttl=51 time=1.78 ms 64 bytes from 8.8.8.8: icmp_seq=6 ttl=51 time=1.87 ms ^C --- 8.8.8.8 ping statistics --- 6 packets transmitted, 6 received, 0% packet loss, time 5009ms rtt min/avg/max/mdev = 1.783/1.861/1.894/0.061 ms [root@75f92bf5b499 /]# 

我发现它可以与互联网社区,你能告诉我关于你的问题的更多信息?

如果您正在使用独立实例,则在实例的network_security组中进行更改并允许出站规则,如果使用ACS,请按照下面的链接https://docs.microsoft.com/en-us/azure/container-service/dcos-swarm/container -SERVICE启用公共访问

Interesting Posts