I have deployed my PostgreSQL database locally with Docker. This is my Docker Compose file:
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.30-alpha
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
# uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
# managementApiSecret: my-secret
prototype: true
databases:
default:
connector: postgres
host: postgres
user: prisma
password: prisma
port: 5432
postgres:
image: postgres
restart: always
environment:
POSTGRES_USER: prisma
POSTGRES_PASSWORD: prisma
volumes:
- postgres:/var/lib/postgresql/data
volumes:
postgres:
I've started this with docker-compose up -d
.
The Docker containers are running:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26b14120f89f prismagraphql/prisma:1.30-alpha "/bin/sh -c /app/sta…" 17 minutes ago Up 17 minutes 0.0.0.0:4466->4466/tcp newdm1_prisma_1
05dfdaeaf609 postgres "docker-entrypoint.s…" 17 minutes ago Up 17 minutes 5432/tcp newdm1_postgres_1
Now, for some reason I can't connect using a database GUI (having tried Postico and TablePlus). In both clients, I get the following error:
FATAL: password authentication failed for user "prisma"
I'm 100% sure that I'm providing prisma
as the password as specified in the Docker Compose file.
Also, when I'm connecting to the database using psql
from inside the postgres
Docker container, it does work:
docker exec -it 05dfdaeaf609 bash
Then inside the Docker container I do this:
root@05dfdaeaf609:/# psql -U prisma -W prisma
Password:
psql (11.1 (Debian 11.1-1.pgdg90+1))
Type "help" for help.
prisma=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+--------+----------+------------+------------+-------------------
postgres | prisma | UTF8 | en_US.utf8 | en_US.utf8 |
prisma | prisma | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | prisma | UTF8 | en_US.utf8 | en_US.utf8 | =c/prisma +
| | | | | prisma=CTc/prisma
template1 | prisma | UTF8 | en_US.utf8 | en_US.utf8 | =c/prisma +
| | | | | prisma=CTc/prisma
(4 rows)
prisma=# \c prisma
Password for user prisma:
You are now connected to database "prisma" as user "prisma".
The password I've provided inside psql
was prisma
, similar to the ones I've provided inside Postico and TablePlus.
Is there anything special I need to do when connecting to a PostgreSQL DB in a Docker container?
PORTS
0.0.0.0:4466->4466/tcp
5432/tcp
If you check the ports column of docker ps
command, you would realize that the Postgres port is not exposed to be used by the host machine.
To solve this, you need to add the following to the docker-compose.yml
file:
ports:
- "5432:5432"
Making the full file look like this:
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.30-alpha
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
# uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
# managementApiSecret: my-secret
prototype: true
databases:
default:
connector: postgres
host: postgres
user: prisma
password: prisma
port: 5432
postgres:
image: postgres
restart: always
ports:
- "5432:5432"
environment:
POSTGRES_USER: prisma
POSTGRES_PASSWORD: prisma
volumes:
- postgres:/var/lib/postgresql/data
volumes:
postgres:
and then you need to run docker-compose up -d
to apply the new changes. When setup correctly, the PORTS
column of docker ps
should look like this
PORTS
0.0.0.0:4466->4466/tcp
0.0.0.0:5432->5432/tcp