#### How to run several database instances on the same host in docker?

For example we have such docker-compose configuration:

version: '3'
services:
web:
build:
context: .
dockerfile: Dockerfile
ports:
- "8069:8069"
volumes:
- .:/code
depends_on:
- postgres1
- postgres2
postgres1:
image: postgres:11
environment:
- POSTGRES_DB=my_postgres1
- POSTGRES_USER=user
volumes:
- postgres1:/var/lib/postgresql/data
postgres2:
image: postgres:11
environment:
- POSTGRES_DB=my_postgres2
- POSTGRES_USER=user
volumes:
- postgres2:/var/lib/postgresql/data

volumes:
postgres1:
postgres2:


Here we have two database instances which run on separated hosts postgres1 and postgres2. And web service should have access to them from one hostname.

There is no need to access services outside the docker, e.g. third service must have access to these databases from one host. It’s a limitation of the system that used, it’s can not deal with databases from different hosts.

It is possible to attach these instances to one shared host, e.g. get access to my_postgres1 and my_postgres2 databases from one host?

Source: StackOverflow