Using UFW Firewall with Docker Containers

Running Docker containers with UFW firewall setup can be challenging because Docker manipulates iptables rules by default. However, with some configuration, you can ensure both Docker and UFW work well together. Below is a step-by-step guide to configure Docker to not interfere with iptables and manually set up UFW rules.

1. Configure Docker Daemon, make “iptables”: false

sudo vi /etc/docker/daemon.json

should like below:

{
    "runtimes": {
        "nvidia": {
            "path": "nvidia-container-runtime",
            "runtimeArgs": []
        }
    },
    "iptables": false
}

2. Restart Docker

sudo systemctl restart docker

3. Modify UFW Forward Policy

sudo sed -i -e 's/DEFAULT_FORWARD_POLICY="DROP"/DEFAULT_FORWARD_POLICY="ACCEPT"/g' /etc/default/ufw

4. Reload UFW to apply the changes:

sudo ufw reload

Reference:

留下评论

通过 WordPress.com 设计一个这样的站点
从这里开始