Expose docker port to internal network only

这一生的挚爱 提交于 2020-06-13 04:55:01

问题


Running numerous dockers right now on a new build for a homelab server and trying to make sure everything is locked down and secure. I use the server for a variety of things, both requiring access from the outside world (nextcloud) and things that I will only access from my internal network (plex). Of course the server is behind a router that limits open ports but looking for additional security - I would like to restrict those dockers that I want to only access via internal network, to 192.168.0.0/24. That way, if somehow a port became open on my router, it would not be exposed (am I being to paranoid?).

Currently docker-compose files are exposing ports via:

....

 ports:
   - 8989:8989
....

This is of course works fine but is accessible to the world should I open the port on my router. I know i can bind to localhost via

....
 ports:
   - 127.0.0.1:8989:8989
....

But that doesn't help me when I'm trying to access the docker from my internal network. I've read numerous articles regarding docker networks and various flags and also read about possibility iptables solution.

Any guidance is much appreciated.

Thanks,


回答1:


Simply do not declare any ports in docker-compose, they are automatically visible between containers.

I use an elasticsearch container in this way and a separate kibana can connect to it by the server name declated on the yml.


if somehow a port became open on my router, it would not be exposed

Using this procedure the ports are never visible outside the docker environment (i.e. outside == in your local network).

If your concern is that ports are published in your LAN when doing the procedure I told you, they are not.



来源:https://stackoverflow.com/questions/56051409/expose-docker-port-to-internal-network-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!