简体   繁体   English

如何将外部IP添加到Docker容器?

[英]How to add an external IP to a Docker container?

I've been studying Docker and all the options available. 我一直在研究Docker及其所有可用选项。 And I have a VPS with 3 extra static IPs. 我有一个带有3个额外静态IP的VPS。

The idea is to connect each container to a different IP or maybe add 3 networks with different containers and having each network connected to a different IP. 这个想法是将每个容器连接到一个不同的IP,或者添加3个具有不同容器的网络,并将每个网络连接到一个不同的IP。 I saw few days ago some tutorials in the internet but I didn't saved them and I can't find them any more. 几天前,我在互联网上看到了一些教程,但是我没有保存它们,也找不到了。

The IPs are static and were delivered by our ISP (ovh). IP是静态的,由我们的ISP(ovh)提供。

So far I tried to connect to IPs using subnet xx.xx.xx.xx/32 (only 1 IP) but it gives me error 到目前为止,我尝试使用子网xx.xx.xx.xx / 32(仅1个IP)连接到IP,但这给了我错误

PS. PS。 I'm newbie at Docker. 我是Docker的新手。

Edit 编辑

Just tried this code 刚刚尝试过此代码

docker network create \
  --driver=bridge \
  --subnet=AAA.BBB.CCC.DDD/32 \
  --ip-range=AAA.BBB.CCC.DDD/32 \
  --gateway=AAA.BBB.CCC.DDD \
  br0

and I'm getting the current error 我正在得到当前错误

Error response from daemon: failed to allocate gateway (AAA.BBB.CCC.DDD): No available addresses on this pool

Also AAA.BBB.CCC.DDD stands for the public IP coming from the ISP AAA.BBB.CCC.DDD也代表来自ISP的公共IP

An ip adress resolves to a certain place (if your dns server is able to resolve it at all) In this case i'm assuming that the static IP's resolve to the same machine: try to confirm that by running IP地址解析到某个位置(如果您的dns服务器完全能够解析它)在这种情况下,我假设静态IP解析到同一台计算机:尝试通过运行来确认

Host xxx.xxx.xxx

note: use the ipv4 address so omit the slash If the same hostname is returned, my assumption is correct. 注意:使用ipv4地址,因此省略斜杠。如果返回相同的主机名,我的假设是正确的。

On this host, each container will have to expose a port and they can't use the same one. 在此主机上,每个容器都必须公开一个端口,并且它们不能使用相同的端口。 (one port per application) (每个应用程序一个端口)

So you'l either have to navigate to an ip followed by a colon and a port number... Or you can omit the port and have a web server like apache or nginx listen on the default port (80) and configure the routing based on the request received. 因此,您要么必须导航到一个IP,后跟一个冒号和一个端口号……要么您可以忽略该端口,并让apache或nginx这样的网络服务器监听默认端口(80),并配置基于根据收到的请求。 (then you route it to the individually exposed ports, but this way the client doesn't have to know about those) (然后将其路由到单独暴露的端口,但是这样客户端不必知道这些端口)

Hopefully this gives you some pointers to investigate the options for your goals. 希望这可以为您提供一些指导,以研究实现目标的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM