I have two servers. First – with docker and certain container. Second – with database.
These servers are in one local network. I want to connect to second server’s database from container running on first server.
I would like to solve it using docker network, but i have no idea what should i do.
2
Answers
Okay, i figured out. It is possible out of the box using network driver "bridge". By default, containers connect to network with driver "bridge", which allow connections from docker container by ip in host's local network.
Example:
First server with postgres in container has 192.168.0.4 local ip. We should use port forwarding to allow connections by 192.168.0.4:5432.
Second server with postgres in container has 192.168.0.3 local ip. From inside this container connection by host local ip - works
Removing network bridge from second server's container disallows connections like that.
Try this example connecting a DB to another container, like described at documentation
Reference: multi container