1

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.

meowDestroyer
  • 125
  • 1
  • 2
  • 7
  • I answered that other question explaining what `localhost` means; you can't use it like this. You should be prepared to change your property file on each deployment. (What if you deploy your application on a cloud provider, they have a database service, and you don't control the host name?) – David Maze Aug 03 '18 at 21:36
  • I read over your other post. After discussion with team, decided to change properties instead. Thank you. – meowDestroyer Aug 03 '18 at 22:36

0 Answers0