Docker Compose
This page contains information about docker compose.
Postgres
To connect to a postgres server running in a docker compose cluster you can use a couple of different approaches.
Port mapping
Lets say that you have the following declaration of a postgres server in a docker-compose.yaml file.
version: '3'
services:
postgres:
image: postgres:latest
Then you can map the postgres servers network port 5432 to the host port 5433 by adding the following port mapping.
version: '3'
services:
postgres:
image: postgres:latest
- ports: "5433:5432"
You can now connect to the server using the following psql command.
psql -h localhost -p 5433 -U username
You can also use the following pgcli command.
pgcli -h localhost -p 5433 -u username
Running psql on the server
Another approach is to connect to the postgres server in docker compose and run psql directly on the server machine.
docker-compose run --rm postgres psql --host=postgres --username=postgres