Search code examples
dockerdocker-composeiptables

How do I disable all the docker rules that are added to iptables for public accces?


I am using docker-compose and just found out all my exposed ports from docker-compose.yml are actually added to iptables to allow world access. No idea but this leaves me with a huge security hole.

The docker page says to run: iptables -I DOCKER-USER -i ext_if ! -s 192.168.1.1 -j DROP

but that does nothing for me. I can still access my db server remotely without tunneling.

I'm not sure what my local ip address would be. I still want to allow internal connections on the host OS to connect to those ports, but not the world.


Solution

  • If you don't want the exposed ports to be publically available, there are easier solutions than mucking about with Docker's iptables rules.

    1. Just don't expose them.

      You don't need to expose ports just to access a service. You can access any open container ports simply by connecting to the container ip address.

    2. Expose them only on localhost.

      Instead of writing -p 8080:8080, which exposes container port 8080 on host port 8080 on all interfaces, write -p 127.0.0.1:8080:8080, which will expose the port only on the loopback address. Now you can reach it on your host at localhost:8080, but it won't be available to anyone else.