0

I'am working on this simple docker-compose file. It starts a node.js server that connects to a postgresql database hosted by the host machine.

version: '3'
services:
  node-server:
    build:
      context: ./docker-test
    networks:
      - my-network
    extra_hosts:
      - "db-server:172.17.0.1"
networks:
  my-network:
    driver: bridge

Here I'am appending a new host entry db-server which gets the value of the docker0 interface ip.

Is there a solution to dynamically set the "db-server" to my-network gateway ip?

Wassim
  • 56
  • 1
  • 5
  • This topic is discussed at some length 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); do the solutions there work for you? – David Maze Apr 07 '20 at 17:20
  • Thanks for your response. I tried to run this command from th dockerfile to set a host entry manually `RUN echo "$(ip -4 route list match 0/0 | cut -d' ' -f3) db-server" >> /etc/hosts` It didn't work because docker creates a new /etc/hosts file when the container is already up. – Wassim Apr 08 '20 at 16:19

0 Answers0