Let's say I want a docker-compose.yml that sets 2 services : a postgresql server and adminer (a kind of phpmyadmin). If I declare
# docker-compose.yml
version: '3.1'
services :
myservername:
image: postgres:10-alpine
ports:
- 5432:5432
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: mydb
admin:
image: adminer
restart: always
ports:
- 8080:8080
With a docker-compose up -d and then on localhost:8080 I can connect to postgres :
That works like a charm. Perfect. But....
But due to specific configurations files in my project, I need that the postgres server name be localhost. So I tried :
# docker-compose.yml
version: '3.1'
services :
localhost: # <----- that's the change
image: postgres:10-alpine
ports:
- 5432:5432
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: mydb
admin:
image: adminer
restart: always
ports:
- 8080:8080
And when I try to connect :
SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? could not connect to server: Address not available Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?

Any idea ?
