question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma doesn't resolve the names of docker containers from within other containers in OSX Docker

See original GitHub issue

Bug description

Prisma works if I give it an ip address, but not a resolvable service name of a container

How to reproduce

docker-compose:

services:
  app:
    image: app
    platform: linux/arm64/v8
    ports:
      - "3000:3000"
    depends_on:
      - postgres
    environment:
      - "DATABASE_URL=postgresql://test:test@postgres:5432/test?schema=public"
    entrypoint: ["/usr/bin/dumb-init", "--", "./utils/wait-for-it.sh", "postgres:5432", "--"]
    command: [
        "/bin/bash",
        "-c",
        "pnpm run prisma-generate
        && pnpm exec prisma migrate dev
        && pnpm run dev -w",
      ]
    volumes:
      - $HOME/.aws:/root/.aws
  postgres:
    hostname: postgres
    image: postgres:14
    restart: always
    volumes:
      - postgres:/var/lib/postgresql/data
    environment:
      - "POSTGRES_PASSWORD=test"
      - "POSTGRES_DATABASE=test"
      - "POSTGRES_USER=test"
    ports:
      - "5432:5432"
volumes:
  postgres:
    name: db

This doesn’t work.

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "test", schema "public" at "postgres:5432"

Error: P1001: Can't reach database server at `postgres`:`5432`

BUT if I do an ip lookup in a shell and set DATABASE_URL=postgresql://test:test@172.23.0.2:5432/test?schema=public, it works. Lit export DATABASE_HOST=$(nslookup ${DATABASE_HOST?} | awk '/^Address: / { print $2 ; exit }')

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "test", schema "public" at "172.23.0.2:5432"

Already in sync, no schema change or pending migration was found.

And psql resolves this perfectly.

app# psql postgresql://test:test@postgres:5432/test
psql (14.2 (Debian 14.2-1.pgdg100+1))
Type "help" for help.

test=#

Expected behavior

Prisma needs to resolve my docker container’s hostname to a valid ip address or I need a workaround that isn’t hard-coding IP’s all over the place.

Prisma information

Environment & setup

  • OS: OSX Monterey 12.3 running a Node:16-based Docker image. Tried to replicate on Ubuntu 20.04 running latest Docker and I could not replicate at all.
  • Database: PostgreSQL
  • Node.js version: v16.14.2

Prisma Version

prisma                  : 3.8.1
@prisma/client          : 3.8.1
Current platform        : linux-arm64-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at ../../node_modules/.pnpm/@prisma+engines@3.8.0-43.34df67547cf5598f5a6cd3eb45f14ee70c3fb86f/node_modules/@prisma/engines/libquery_engine-linux-arm64-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at ../../node_modules/.pnpm/@prisma+engines@3.8.0-43.34df67547cf5598f5a6cd3eb45f14ee70c3fb86f/node_modules/@prisma/engines/migration-engine-linux-arm64-openssl-1.1.x)
Introspection Engine    : introspection-core 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at ../../node_modules/.pnpm/@prisma+engines@3.8.0-43.34df67547cf5598f5a6cd3eb45f14ee70c3fb86f/node_modules/@prisma/engines/introspection-engine-linux-arm64-openssl-1.1.x)
Format Binary           : prisma-fmt 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at ../../node_modules/.pnpm/@prisma+engines@3.8.0-43.34df67547cf5598f5a6cd3eb45f14ee70c3fb86f/node_modules/@prisma/engines/prisma-fmt-linux-arm64-openssl-1.1.x)
Default Engines Hash    : 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f
Studio                  : 0.452.0
Preview Features        : interactiveTransactions

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:23 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
callumthomsoncommented, Sep 27, 2022

Update: it works on node 16.17.0 if I use ?connect_timeout=300 at the end of my DB connection string.

1reaction
osaaama01commented, Nov 20, 2022
- docker-compose -f docker-compose-db.yml up -d
- export DB_URL=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.Gateway}}{{end}}' db)
- DB_HOST=${DB_URL} docker-compose -f docker-compose.yml up --abort-on-container-exit
- docker-compose down --remove-orphans -v

I am using these commands for my CI. It starts the container of MySQL in a separate compose file named docker-compose-db, extracts the IP for that container and then passes the IP as an env variable for the next compose file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

docker-compose up issue Using Docker Apple M1
Solution: Right now: I plan running my images on an x86 computer the time for this issue to be fixed.
Read more >
Accessing prisma service from other docker container
Hi! I am trying to dockerize my Node.js app that is using Prisma Client. So in docker-compose.yml I have 3 services: server, prisma...
Read more >
Vulnerability scanning for Docker local images
Vulnerability scanning for Docker local images allows developers and development teams to review the security state of the container images and take actions ......
Read more >
NestJS + Redis + Postgres Local Development With Docker ...
Docker Compose set up for NestJS, Redis and Postgres ... other Nest container configs depends_on: - redis redis: # Name of container image: ......
Read more >
Getting Start with twistcli | Prisma Developer Docs
For image scanning, Docker Engine must be installed on the executing machine. ... inside a container, so you should only use this approach...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found