我有一个设置,我在docker集装箱运行我的网站的所有部分。 监听端口80和443的我的nginx在一个容器中运行。
363292a98545 scivm/nginx-django-scivmcom:latest /usr/bin/supervisord 12 days ago Ghost 0.0.0.0:40001->22/tcp, 88.198.57.112:443->443/tcp, 88.198.57.112:80->80/tcp lonely_feynmann
我想在另一个容器中设置一个服务的代理。 此容器绑定到主机上的端口3000:
b38c8ef72d0a mazzolino/strider-dind:latest wrapdocker /usr/bin/ 41 minutes ago Up 41 minutes 0.0.0.0:3000->3000/tcp, 22/tcp, 27017/tcp distracted_einstein
我的docker主机上的iptables如下所示:
root@Ubuntu-1204-precise-64-minimal /var/run # iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ACCEPT tcp -- anywhere anywhere tcp dpt:http ACCEPT tcp -- anywhere anywhere tcp dpt:https ACCEPT tcp -- anywhere anywhere tcp dpt:8000 DROP all -- anywhere anywhere Chain FORWARD (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED Chain OUTPUT (policy ACCEPT) target prot opt source destination
从容器内,由于iptablesconfiguration,我无法连接到主机上的端口3000。
我不想打开端口3000到公共互联网。
有没有办法打开容器和端口3000上的主机之间的直接桥梁?
或者我应该修改我的iptables接受dockerip范围?
所有你需要的是Docker的链接function 。
只是摆脱所有你试图做的复杂的东西,并开始使用命名的容器,然后将它们链接到对方。
埃利亚斯的回答是正确的,但是这个联系是漫长而令人困惑的。 这里有一个简单的总结:
首先,运行容器来链接并命名它:
sudo docker run -d --name db training/postgres
然后运行其他容器,将其链接到第一个容器:
sudo docker run -d -P --name web --link db:db training/webapp python app.py
从第一个容器到第二个容器的链接放在/etc/hosts 。 所以你可以像使用主机名一样使用它。 例如:
sudo docker run --name web --link db:db training/webapp ping db