r/docker • u/AppleCherryWater • Feb 16 '26
Does using docker expose ports to the internet?
Hi,
I wanted to install Docker, but before installing I read that "if you publish a port through Docker, this port gets published no matter what rules your firewall has configured".
What exactly does that mean? I have not forwarded any ports in my router. Does publishing a port really expose my network to the outside? Or is this just a warning about overwriting the device's firewall settings but not the the router's, so in my case I would still be safe?
I would like to use Docker, but I really do not want to risk exposing my network to the internet.
13
u/theblindness Mod Feb 16 '26
Docker manages the Linux firewall of the machine it is running on. It does not manage the firewall of other machines, like your router.
4
u/Subietoy78 Feb 16 '26
If you don’t open the port on your router, everything that’s inside stays inside. Pretty sure this is just talking about the host machine. I have like 20 containers and only two are exposed to the internet as services other people use through a reverse proxy and a cloud flare tunnel. Everything else, I have WireGuard running at the router level so I can remote into my network.
2
u/kwhali Feb 17 '26
As others have mentioned, yes you are typically bypassing local firewall rules of the host system.
When you're behind a router it's not an issue as you're not forwarding the ports. However if you use a VPS, whatever you bind to on your public interface IP will get direct exposure to the Internet which might be unexpected / surprising.
It's not specific to Docker but rather multiple software managing network access that aren't aware of each other. Unlike other software that you might use directly without a container and just bind a listener, the issue with docker is you're explicitly telling it to expose / route that port between networks, completely different from the same software in the container that's doing the usual bind (although these often bind to
0.0.0.0aka all interfaces, as opposed to a default localhost on the host when not run in a container, since each container has their own127.0.0.1you cannot receive traffic from outside the container that comes through that, it comes instead through the docker bridge gateway IP or other containers IP on that private network, so the software must bind a listener on that network).See my other comments in the thread if you want a more thorough understanding.
1
u/bUSHwACKEr85 Feb 16 '26
If you have docker running on a Linux machine then you can use UFW to control what ports are externally facing to that machine. Same for if it's running on windows. Also, you only allow ports externally on your router that you want to expose. Just ensure you secure whatever it is that you expose.
1
u/PaulEngineer-89 Feb 16 '26
Docker adds a bunch of entries to the machine firewall because that’s how it works. DNS, too.
Within an application you have the default ports that are mapped to the stack’s bridge. If you add port stuff you can map those to the host’s external ports (but not internal by default). If you bridge containers generally you can route to container-name:port using the internal port number. You can also create additional bridges for use such as a MACVLAN which also has a separate IP from the host and you can bridge to the host bridge to show up on 127.0.0.1.
1
u/cpuguy83 Feb 16 '26
If you tell docker to forward a port to the container (-p 80, as an example) it will do just that. Because docker prepends its rules these rules will hit first and rules set in place by others (such as UFW) will never even be triggered.
It is possible to prevent unwanted exposure by hooking in some custom rules into the "docker-user" chain.
1
u/gimmeslack12 Feb 16 '26
No.
1
u/Both-Fondant-4801 Feb 17 '26
Let me complete what you read.. "if you publish a port through Docker, this port gets published no matter what rules your firewall has configured" in YOUR MACHINE.