简体   繁体   English

如何通过 ip 地址访问 docker 容器

[英]How can I access a docker container via ip address

I'm trying to replace our vagrant development setup with docker.我正在尝试用 docker 替换我们的 vagrant 开发设置。 I'd like to be able to use an ip like 10.10.10.10 for my docker container and allow developers to access their container via that IP.我希望能够为我的 docker 容器使用像 10.10.10.10 这样的 ip,并允许开发人员通过该 ZA12A3079E14CED46E69BA52B8A90B21 访问他们的容器。 I'm currently using docker on Mac OS, but some developers use Windows.我目前在 Mac OS 上使用 docker,但一些开发人员使用 Windows。

How can I make this work?我怎样才能使这项工作?

If I'm reading the docs for Docker for Mac correctly, that's not possible如果我正确阅读了 Docker for Mac 的文档,那是不可能的

Per-container IP addressing is not possible每个容器的 IP 寻址是不可能的

The docker (Linux) bridge network is not reachable from the macOS host.无法从 macOS 主机访问 docker (Linux) 桥接网络。

and

I want to connect to a container from the Mac我想从 Mac 连接到容器

Port forwarding works for localhost;端口转发适用于本地主机; --publish, -p, or -P all work. --publish、-p 或 -P 都有效。 Ports exposed from Linux are forwarded to the Mac.从 Linux 公开的端口被转发到 Mac。

Our current recommendation is to publish a port, or to connect from another container.我们目前的建议是发布一个端口,或者从另一个容器连接。 Note that this is what you have to do even on Linux if the container is on an overlay network, not a bridge network, as these are not routed.请注意,如果容器位于覆盖网络而不是桥接网络上,即使在 Linux 上,这也是您必须执行的操作,因为这些未路由。

There is also a pretty interesting discussion here about why there is no docker0 bridge to access containers directly.这里还有一个非常有趣的讨论关于为什么没有docker0网桥可以直接访问容器。 This comment suggests a workaround that might be good enough for your needs. 此评论提出了一种可能足以满足您需求的解决方法。

docker inspect码头工人检查

foundip address发现地址

Then u can connect it by ip address然后你可以通过ip地址连接它

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

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