Tag: iptables

如何将docker容器中的单个端口redirect到容器的主机?

为了使项目的开发更容易,我在docker容器中放了一些它依赖的服务。 这使得项目configuration中的“localhost”在传递给其中一个容器时会有所不同。 编辑 要清楚,我试图转发一个容器的端口到主机,所以当容器中运行的进程试图访问localhost:5432时,它连接到主机的端口5432。 EndEdit中 我目前正在使用 HOST_IP=`ip route | grep default | awk '{ printf "%s",$3 }'` cat /etc/hosts | sed "s/127.0.0.1/$HOST_IP/" > /tmp/etc_hosts cp /tmp/etc_hosts /etc/hosts 将任何目标为'本地主机'redirect到容器的主机。 它在这种情况下工作,但我宁愿find一种方法来做到这一点,只为所需的端口,因为我希望它不会在其他情况下工作。 这是我想出来做的,但是这不起作用。 当容器中的连接是localhost:5432时,它将尝试连接到容器的5432而不是主机的: # — These are the things that should make redirecting port 5432 to the host machine # work, provided the container is run in […]

在基于alpinelinux的docker容器中安装iptables

我正在写一个dockerfile,我需要在docker容器中安装IPtables。 我需要添加一个规则到IP表,因为我试图在“主机”networking模式下运行,似乎我需要为此安装IPtables。 当我尝试如下包含规则时,出现以下错误。 iptables -I INPUT -p tcp -m tcp –dport 8080 -j ACCEPT iptables v1.6.0: can't initialize iptables table `filter': Permission denied (you must be root) 也许iptables或你的内核需要升级。 是否有可能以root权限运行iptables。

阻止从Docker容器到私有IP的传出连接

我们使用Docker在服务器上运行的一些服务尝试连接到私有IP地址(10.0.0.0/8,192.0.0.0/16,172.16.0.0/12,100.64.0.0/10)。 这种行为是正常的,但我们的服务器提供商检测到这种stream量,并发送警报 我们只想停止传出stream量,而不是使用iptables传入。 这是我们目前的设置: -A OUTPUT -d 192.168.0.0/16 -m owner –uid-owner `id -u dockeruser` -j REJECT –reject-with icmp-port-unreachable -A OUTPUT -d 100.64.0.0/10 -m owner –uid-owner `id -u dockeruser` -j REJECT –reject-with icmp-port-unreachable -A OUTPUT -d 172.16.0.0/12 -m owner –uid-owner `id -u dockeruser` -j REJECT –reject-with icmp-port-unreachable -A OUTPUT -d 10.0.0.0/8 -m owner –uid-owner `id -u […]

Docker是否在iptables中为桥接networking自动化IP伪装规则?

我有一台QNAP RAID机器上运行docker-1.9.1 。 它具有使用子网10.0.3.0/24的默认bridgenetworking。 在iptables中,我在nat表中看到一条规则: -A POSTROUTING -s 10.0.3.0/24 ! -d 10.0.3.0/24 -j MASQUERADE 我假设Docker自己创build了这个规则。 我创build了一个新的桥梁networking: docker network create \ –gateway=10.0.5.1 \ –subnet=10.0.5.0/24 \ -o "com.docker.network.bridge.host_binding_ipv4"="0.0.0.0" \ -o "com.docker.network.bridge.enable_icc"="true" \ -o "com.docker.network.driver.mtu"="1500" \ -o "com.docker.network.bridge.name"="lxcbr1" \ -o "com.docker.network.bridge.enable_ip_masquerade"="true" \ isolated_nw 这不会在iptables中创build一个规则。 我错过了一个步骤? 下面是完整的设置命令和结果,复制@larsks的例子: [/share/Containers] # docker –version Docker version 1.9.1, build 147ce3e [/share/Containers] # iptables […]