Open7
Nest × Prisma × Docker × M1 Mac で npx prisma migrate dev ができない
npx prisma migrate dev ができない
/var/www # npx prisma migrate dev
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": MySQL database "nest", schema "public" at "db:3306"
Error: Unable to establish a connection to query-engine-node-api library. It seems that the current architecture arm64 is not supported, or that libc is missing from the system.
Details: Unable to require(`/var/www/node_modules/@prisma/engines/libquery_engine-linux-arm64-openssl-3.0.x.so.node`)
Error loading shared library ld-linux-aarch64.so.1: No such file or directory (needed by /var/www/node_modules/@prisma/engines/libquery_engine-linux-arm64-openssl-3.0.x.so.node)
[Context: getDmmf]
Prisma CLI Version : 4.8.1
設定・環境
"prisma": "^4.8.1"
"@prisma/client": "^4.8.1"
Dockerfile
FROM node:16-alpine
RUN apk update \
&& npm install -g npm@latest @nestjs/cli
WORKDIR /var/www
docker-compose.yml
version: '3.8'
services:
nest:
container_name: nest-practice
build:
context: .
dockerfile: ./docker/node/Dockerfile
ports:
- 3333:3000
volumes:
- type: bind
source: ./app
target: /var/www
tty: true
depends_on:
db:
condition: service_healthy
db:
container_name: nest-db
image: mysql:8.0
platform: linux/amd64 # M1 Mac以外の場合コメントアウト
ports:
- 3304:3306
volumes:
- type: volume
source: db
target: /var/lib/mysql
- type: bind
source: ./docker/db/my.cnf
target: /etc/mysql/conf.d/my.cnf
- type: bind
source: ./docker/db/sql
target: /docker-entrypoint-initdb.d
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
MYSQL_DATABASE: ${DB_DATABASE:-nest}
MYSQL_USER: ${DB_USER:-nest}
MYSQL_PASSWORD: ${DB_PASSWORD:-secret}
TZ: Asia/Tokyo
LANG: ja_JP.UTF-8
LANGUAGE: ja_JP:ja
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "${DB_USER:-nest}", "-p${DB_PASSWORD:-secret}"]
interval: 6s
timeout: 60s
retries: 10
start_period: 60s
volumes:
db:
.env
DATABASE_URL="mysql://nest:secret@db:3306/nest?schema=public"
SHADOW_DATABASE_URL="mysql://nest:secret@db:3306/nest_shadow?schema=public"
とりあえず alpine だと openssl とかが入ってないのが理由(?)でダメらしい
https://github.com/prisma/prisma/issues/16232#issuecomment-1336481295 にある通り、
Dockerfile
FROM node:16-slim
RUN apt-get update \
&& apt-get install -y openssl
RUN npm install -g npm@latest @nestjs/cli
WORKDIR /var/www
のようにして動かしてみた。
しかし、Can't reach database server at db:3306
とのこと・・・
Docker Compose 使ってるし、network は作成されてるはずなのに。
DATABASE_URL="mysql://nest:secret@db:3306/nest?schema=public&connect_timeout=300"
SHADOW_DATABASE_URL="mysql://nest:secret@db:3306/nest_shadow?schema=public&connect_timeout=300"
としたら通った。
ただベストプラクティスではない気がする。。
さっきの StackOverflow の1つ下のコメントにある通り、node のバージョンを18にして build し直したらいけた。
Dockerfile
FROM node:18-slim
RUN apt-get update \
&& apt-get install -y openssl
RUN npm install -g npm@latest @nestjs/cli
WORKDIR /var/www
$ docker compose up -d --build
諸々の理由はわかってないので、時間ある時調査します🙏