如何使Docker容器通过IP访问其他网络机器? [英] How to make Docker container accessible to other network machines through IP?

查看:746
本文介绍了如何使Docker容器通过IP访问其他网络机器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一些必须由同一网络上的其他计算机访问的docker容器。

I need to create some docker containers that must be accessed by other computers at the same network.

问题是当我创建容器时,Docker只能在主机中获取IP地址。

Problem is that when I create the container, Docker gets IP addresses valid only within the host machine.

我已经看了Docker文档(网络),但没有任何工作。

I already took a look at Docker documentation (Networking) but nothing has worked.

如果我在我的...上运行 ifconfig 机器我的IP地址是 172.21.46.149 。当我进入容器(Ubuntu)并运行 ifconfig 时,IP地址为 172.17.0.2 。我需要Docker来获得,例如 172.21.46.150

If I run ifconfig on my machine my IP address is 172.21.46.149. When I go inside the container (Ubuntu) and run ifconfig the IP address is 172.17.0.2. I need Docker to get, for example, 172.21.46.150.

我该怎么做?

推荐答案

您必须在主机上创建一个桥,并将该桥分配给容器。这可能会帮助您: https://jpetazzo.github.io / 2013/10/16 / configure-docker-bridge-network /

You have to create a bridge on your host and assign that bridge to the container. This may help you: https://jpetazzo.github.io/2013/10/16/configure-docker-bridge-network/

这篇关于如何使Docker容器通过IP访问其他网络机器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆