Access 192.168.* networks from within docker swarm

I’m running services using docker-compose connected to overlay network in swarm mode.

May I know is there anyway I can access services located in our network via the 192.168* IP ranges? Some of
our services are not stable running on docker (etc redis) and we are hoping we can connect to the redis server via the private area network instead of via public address.

By default a container can access whatever the host is able to access.

As long as the target ip is in the same subnet, or is reachable via a route and no firewall prevents the communication, there is no reason it should not work (if you run docker in the default configuration).

OH! thank you!.

I guess I fell in to a blind spot because I was trying to test from within the container, that is running on the same VPS as the redis service.

I enabled UFW for all my local IP address range 192.168.0.0/16 to port 6379 but apparently it’s insufficient since the docker is accessing my 192.168 network IP from different ip address.

i found these with ip address | grep inet

inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
inet 172.18.0.1/16 brd 172.18.255.255 scope global br-b94231dd5ca5
inet 172.21.0.1/16 brd 172.21.255.255 scope global docker_gwbridge

and I added all 3 IP ranges to the ufw table and it appears to be working even if the docker container is on the same server as my redis.

I am able to use redis-cli within the docker container now, it seems.

Please correct me if I am doing anything that is insufficient. I m afraid of hiccups later on.

From UFW’s perpsective, the container is comming from a different subnet :slight_smile:

Yes i didn’t think of that, I just thought I couldn’t access private network from within the container. Thank you for clearing my doubts leading me to the correct solutions.