Docker actually provides DNS support for networking between containers. This means that if you define your database connection as:
This will resolve
redis to the correct network address, given that you fulfill the following:
- All containers are on the same network
- The containers have been named
This can either be done manually by starting both instances via the cli or automated with a docker compose script, which is my recommendation. In the compose script, from version 3, you would define the both services (aka the containers):
command: bash -c "./start.sh"
And at the end of the file, define the network both instances should be connected to: