通过端口转发链接Docker容器? [英] Docker container linking via port forwarding?

查看:97
本文介绍了通过端口转发链接Docker容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎向其他Docker容器公开服务的首选方法是容器链接,它设置了一些环境变量,然后您必须在应用程序代码中使用这些环境变量来查找主机名和端口号:

It seems that the preferred way to expose services to other Docker containers is container linking, which sets some environment variables that you then have to use in your application code to look up host names and port numbers:

 psql -h $PG_PORT_5432_TCP_ADDR -p $PG_PORT_5432_TCP_PORT 

是否存在未通过端口转发以对应用程序透明的方式完成此操作的原因?这样一来,就像我可以在标准端口80上的容器中运行Web服务器并让Docker找出要使用的实际端口一样,我可以做

Is there a reason this is not done via port forwarding in a way that is transparent to the application? So that in the same way that I can just run my web server inside the container on standard port 80 and have Docker figure out what actual port to use, I could just be doing

psql -h 0.0.0.0  # no -p necessary, we use the default port

启动docker时将设置端口转发,就像服务器端口一样。

The port forwarding would be set up when I start docker, just like with server ports.

推荐答案

这个有可能!实际上,它是由CoreOS团队提出的。您可以在以下博客文章中了解更多信息:

This is possible! It has actually be proposed by the CoreOS team; you can read more in the following blog post:

http://coreos.com/blog/Jumpers-and-the-software-defined-localhost/

Docker很快将允许启动一个共享另一个容器的网络名称空间的容器。它将有助于解决这些情况(并在短期内允许您很轻松地完成您的建议)。

Docker will soon allow to start a container sharing the network namespace of another container; it will help with those scenarios (and in the short term, it will allow to do what you suggest very easily).

这篇关于通过端口转发链接Docker容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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