Skip to main content

UFW and Docker

When running containers in Docker, you will come across the need for a container to gain access to a resource on the host.
If you have UFW firewall enabled, you will need to allow ingress from the docker network, running on the host.

To identify the docker network, run this:

sudo docker network ls

It will return the list of docker networks:

image.png

Next, you need to identify the docker network where your containers are addressed.
To do this, run the following on each network name:

sudo docker network inspect bridge

The above command will give you a list of containers and their addresses and subnets.

Next, you will update the ufw firewall rules to allow incoming connection from the docker subnet, like this:

sudo ufw allow from 172.17.0.0/16

You can check the status and rules with:

sudo ufw status

This will return something like this:

image.png

Now, you should be able to access host resources from a docker container, with UFW enabled.