1

I created a microservice environment, more precisely 5 services, where they are connected to each other and access the same database (PostgreSQL). After development, I started to create the docker images for the services. All images have been created, however, I can not put postgreSQL in the docker environment, since it is already running on the machine in localhost, and other applications depend on it, so I can not migrate to the docker environment. I would like to know if it is possible for my applications to access the database that is outside the environment?

Below, my docker-compose

version: '2'
services:
    server:
        image: microservices/server:latest
        mem_limit: 1073741824 # RAM 1GB
        environment:
          - SPRING_PROFILES_ACTIVE=docker
        expose:
          - "8080"
        ports:
          - "8080:8080"
        networks:
          - microservices
    security-server:
        image: microservices/security-server:latest
        mem_limit: 1073741824 # RAM 1GB
        environment:
          - SPRING_PROFILES_ACTIVE=docker
        depends_on:
          - server
        expose:
          - "8081"
        ports:
          - "8081:8081"
        networks:
          - microservices
        restart: "always"
    api-gateway:
        image: microservices/api-gateway:latest
        mem_limit: 1073741824 # RAM 1GB
        environment:
          - SPRING_PROFILES_ACTIVE=docker
        depends_on:
          - server
          - security-server          
        expose:
          - "9999"
        ports:
          - "9999:9999"
        networks:
          - microservices
        restart: "always"         
    imovel:
        image: microservices/imovel:latest
        mem_limit: 1073741824 # RAM 1GB
        environment:
          - SPRING_PROFILES_ACTIVE=docker
        depends_on:
          - server
          - security-server
          - api-gateway        
        expose:
          - "8082"
        ports:
          - "8082:8082"
        networks:
          - microservices          
        restart: "always" 
    imovel2:
        image: microservices/imovel:latest
        mem_limit: 1073741824 # RAM 1GB
        environment:
          - SPRING_PROFILES_ACTIVE=docker
        depends_on:
          - server
          - security-server
          - api-gateway         
        expose:
          - "9098"
        ports:
          - "9098:9098"
        networks:
          - microservices          
        restart: "always"           
    cliente:
        image: microservices/cliente:latest
        mem_limit: 1073741824 # RAM 1GB
        environment:
          - SPRING_PROFILES_ACTIVE=docker
        depends_on:
          - server
          - security-server
          - api-gateway          
        expose:
          - "8083"
        ports:
          - "8083:8083"
        networks:
          - microservices
        restart: "always"            
networks:
  microservices:
    driver: bridge    

In the link quoted, his problem was that postgres wasn't accepting connections from outside. My problem is more of the beginning, where should I start configuring the connection?

Cristiano Bombazar
  • 984
  • 2
  • 7
  • 15
  • Possible duplicate of [Allow docker container to connect to a local/host postgres database](https://stackoverflow.com/questions/31249112/allow-docker-container-to-connect-to-a-local-host-postgres-database) – David Maze Aug 24 '18 at 20:14
  • @DavidMaze i think is similar, because, his problem it's an error on connect to PostgresSQL. My problem is most of the beginning: How do i start to configure the connection with postgres? One more time, sorry for the english. – Cristiano Bombazar Aug 24 '18 at 20:21

1 Answers1

0

You can specify extra_hosts in the compose format and pass in your host's IP address as an environment variable.

extra_hosts:
       - "my_host:${HOST_IP}"

https://docs.docker.com/compose/compose-file/#extra_hosts

Nick
  • 2,524
  • 17
  • 25