Hi Everyone: question about using a local DB with ...
# orm-help
j
Hi Everyone: question about using a local DB with Docker. In the docs (https://www.prisma.io/docs/run-prisma-server/local-prisma-setup-je3i/#example-docker-compose-setup) it says:
Copy code
prisma is using the postgres-db container as its database. Instead of referencing the database host via an IP address or URL, it simply references the postgres-db image as the database host:
I can connect to my DB using
docker exec -it postgres psql -U prisma
, but how do I connect via a GUI like Postico? Postico expects a host like this: This gives the error "Hostname not found". Can anyone advise if this is possible?
1
j
i believe you would expose the port (3306?) in the docker container, and connect to it directly. Regardless of how prisma connects to it.
syntax:
Copy code
ports:
      - "3306:3306"
and host would be
localhost
j
Hi Jared: thanks for the help. I set up my docker-compose.yml like this:
Copy code
version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.18
    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
        databases:
          default:
            connector: postgres
            host: localhost
            port: 5432
            user: prisma
            password: prisma
            migrations: true
            rawAccess: true
  postgres:
    image: postgres
    restart: always
    ports:
    - 5432:5432
    environment:
      POSTGRES_USER: prisma
      POSTGRES_PASSWORD: prisma
    volumes:
      - postgres:/var/lib/postgresql/data
volumes:
  postgres:
and now it does accept localhost connections from Postico. However, the docker logs are giving this error:
Copy code
prisma_1    | Oct 18, 2018 6:20:03 PM org.postgresql.Driver connect
prisma_1    | SEVERE: Connection error:
prisma_1    | org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
j
i can't see what's wrong. Maybe others can chime in on it
c
in the prisma config, try changing the host from
localhost
to
postgres
docker-compose will set the hostname of each container to the name of the service as defined in the yml (in your case
postgres
)
j
@cedric I have done that, and it works. But then I how would I go about accessing my database via Postico?
c
in postico on your host machine, it should be available at localhost:5432
the
postgres
hostname only applies when the service is being accessed by other docker containers
but on your host machine, when you expose a port everything is exposed on localhost
j
I tried that but it doesn't work, because postgres is not running on localhost. Postico gives the error:
Copy code
could not connect to server: Connection refused
	Is the server running on host "localhost" (::1) and accepting
	TCP/IP connections on port 5432?
c
oh!
try adding quotes around "5432:5432"
in your
ports
config
j
trying now 🙂
dear Cedric you are a genius 🤛
it's working great, the quotes were the problem
c
awesome, yeah that's a super non-intuitive aspect of docker-compose, but yml requires strings with special characters like
:
to be wrapped in quotes
and i believe python's yml parser just cuts off a string before the
:
if you don't quote it
j
i see, got it
j
we did it!
c
🙌
j
@Jared you told me to use quotes too... my bad 🙂
j
¯\_(ツ)_/¯