gpt4 book ai didi

azure - 如何为 Docker 容器启用出站连接?

转载 作者:行者123 更新时间:2023-12-03 11:49:14 27 4
gpt4 key购买 nike

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

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

最佳答案

There is no special network configuration; the default "bridge" mode is used.

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

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

将端口 80 映射到该虚拟机后,我们应该将入站规则添加到 Azure 网络安全组(NSG),我们可以按照这个 article 来添加它。

我们还应该将端口 80 添加到操作系统文件墙入站规则。

<小时/>

更新:

抱歉造成误解。

这是我的测试,我在Azure VM(Ubuntu 16)上安装docker,然后创建一个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 /]#

我发现它可以通过互联网进行交流,您能否向我展示有关您的问题的更多信息?

关于azure - 如何为 Docker 容器启用出站连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47428924/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com