UFW rules don't work with docker

I have a 12.04.4 server, and I have enabled ufw, and have tried to block port 8080. However, it is still open.

$ sudo ufw deny 8080
Rule added
Rule added (v6)

$ sudo ufw status numbered
Status: active

     To                         Action      From
     --                         ------      ----
[ 1] 22                         ALLOW IN    Anywhere
[ 2] 80                         ALLOW IN    Anywhere
[ 3] 8080                       DENY IN     Anywhere
[ 4] 22                         ALLOW IN    Anywhere (v6)
[ 5] 80                         ALLOW IN    Anywhere (v6)
[ 6] 8080                       DENY IN     Anywhere (v6)

Thoughts? I can still access the website that is on 8080. I have rebooted the system several times. The IP address is handled via static assignment, but I can't find anything that would indicate that that is the problem.

The service I'm trying to block is on a docker instance, however this question did not help.


Solution 1:

The docker template that I am using is for Discourse. I solved it by editing the containers/app.yml file to include this under the ''expose' section:

 - "127.0.0.1:20080:80"

This means that it routes port 20080 on 127.0.0.1 to port 80 on the docker instance, thus removing the need entirely for a ufw rule.

Solution 2:

I tested it.

When I enter the command: sudo ufw deny 80, I could connect to myself, But other host could not.

I suggest you try to connect from any other than you.