Home > Mobile >  Create multiple postgres servers with docker compose
Create multiple postgres servers with docker compose

Time:06-28

I'm trying to create multiple postgres services with docker compose, but I can't connect to the second host with the second port 5433:

listings-service-db:
    image: postgres:latest
    environment:
        - POSTGRES_USER=admin
        - POSTGRES_PASSWORD=admin1234
        - POSTGRES_DB=listings
    ports: 
        - "5432:5432"
    restart: always
    volumes: 
        - database-data:/var/lib/postgresql/data/

users-service:
    build: "./users-service"
    depends_on:
        - users-service-db
    volumes:
        - ./users-service:/opt/app/  

users-service-db:
    image: postgres:latest
    environment:
        - POSTGRES_USER=admin
        - POSTGRES_PASSWORD=admin1234
        - POSTGRES_DB=users
    ports: 
        - "5433:5432"
    restart: always
    volumes: 
        - database-data:/var/lib/postgresql/data/

i get this error

enter image description here

even I recover the host well

enter image description here

enter image description here

for the first service it is easily created

CodePudding user response:

the users-service-db must map the right port within the container. also, give them different volumes.

listings-service-db:
  volumes: 
    - database-data-listings:/var/lib/postgresql/data/

users-service-db:
  ports: 
    - "5433:5432"
  volumes: 
    - database-data-users:/var/lib/postgresql/data/
  • Related