What is the best practice of docker + ufw under Ubuntu

后端 未结 8 1362
旧巷少年郎
旧巷少年郎 2020-11-27 10:14

I just tried out Docker. It is awesome but seems not work nicely with ufw. By default, docker will manipulate the iptables a little bit. The outcome is not a bug but not wha

8条回答
  •  臣服心动
    2020-11-27 10:57

    I don't like the operational overhead required by the iptables: false flag in docker daemon. In fact, from what I see, and please correct me if I am wrong, all the solutions are way too complicated hacks.

    Just insert this in /etc/ufw/after.rules, before the *filter section:

    *mangle
    # Allow a whitelisted ip to access postgres port
    -I PREROUTING 1 -s  -p tcp --dport 5432 -j ACCEPT
    # Allow everyone to access port 8080
    -I PREROUTING 2 -p tcp --dport 8080 -j ACCEPT
    # Drop everything else
    -I PREROUTING 3 -p tcp -j DROP
    COMMIT
    

    There is no need to mess with docker networking or with unnecessary hacks.

提交回复
热议问题