I have a java project and I am using docker-compose to run some tests.
In this project, I have a sample.properties file that are being used during the test and it has the following fields:
database_name = some.address
another_db_name = localhost
My compose file looks like this:
services:
some.address:
# this is my database
...
networks:
- network1
localhost:
# this does not work
test:
# runs test
networks:
- network1
In this set up, my test will correctly use the database_name for test, but not for localhost. From what I searched, localhost refers container itself in this context.
I have tried creating aliases but it does not work. In addition, having networks and network_mode = host together in a service is not allowed.
The only way I could get my test to work is to change localhost in properties file to something else, eg) localhost1. Is it possible to somehow refer to a service as "localhost" while being connected to network1? (eg, by not changing my property file).
Thank you.