1
version: '3'
services:
   my_app:
     build: ./api
     environments:
       - DB_HOST=192.168.10.1 #Physical IP database server

Docker Engine Server IP: 192.168.20.1

Beso
  • 1,176
  • 5
  • 12
  • 26
  • ...it looks like you might have clarified, in a comment on an answer, that the database is on a different machine? Broadly, the setup you've shown here should work (use the database's DNS name or IP address as normal). A [mcve] including the actual error message would help clarify what's going on; definitely clarify if the database isn't on the same machine, since that's the case people frequently ask about. – David Maze Jan 05 '21 at 11:36

1 Answers1

0

You should add

network_mode: host

to my_app, and use localhost

https://forums.docker.com/t/option-network-mode-host-in-docker-compose-file-not-working-as-expected/51682

  • I don't need to connect to my localhost, i need to connect to other physical machine in the same network tith my localhost. And i think i need a bridge driver cause my app connect also with others docker containers – Kissema Eduardo Rafael Jan 05 '21 at 09:45
  • https://blog.oddbit.com/post/2014-08-11-four-ways-to-connect-a-docker/ It might help you – Thomas Saison Jan 05 '21 at 09:52
  • Host networking generally disables Docker's networking stack, and things like inter-container communication won't work well. I'd use one of the other solutions described in [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach). – David Maze Jan 05 '21 at 11:34