-
Notifications
You must be signed in to change notification settings - Fork 783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(Serverless: OS Support Initiative): Document how to use Prisma with Docker / Linux Distros #4365
Comments
This follows up on #4303 . |
Follow-up TODOs
|
Working on this draft: How to run Prisma on DockerPrisma supports the most of the popular Docker images for Node.js out of the box. In this tutorial, we'll walk you through the process of setting up a Docker container for a Node.js application that uses Prisma. Given a simple Prisma schema, an empty Postgres database, and a basic Express.js server running on port PreliminariesCreate a new // ./prisma/schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgres"
url = env("DATABASE_URL")
}
model Author {
id Int @id
post Post[]
}
model Post {
id Int @id
user Author @relation(fields: [userId], references: [id])
userId Int
} // ./server.js
const express = require('express')
const app = express()
const port = 3000
const { PrismaClient } = require('@prisma/client')
const client = new PrismaClient()
app.get('/', async (req, res) => {
const data = await client.user.findMany()
res.send(JSON.stringify(data))
})
app.listen(port, () => {
console.log(`App listening at http://localhost:${port}`)
}) // ./package.json
{
"name": "@prisma/docker-tutorial",
"license": "MIT",
"devDependencies": {
"prisma": "4.10.0"
},
"scripts": {
"start": "node server.js"
},
"dependencies": {
"@prisma/client": "4.10.0",
"express": "4.18.2"
}
} ./docker-compose.yml
version: '3.7'
services:
postgres:
image: postgres:15
hostname: postgres_db
restart: always
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=prisma
- POSTGRES_PASSWORD=prisma
ports:
- '5432:5432'
networks:
- prisma-network
prismacmd:
image: prisma-docker-tutorial
stdin_open: true
environment:
- DATABASE_URL=postgresql://prisma:prisma@postgres_db:5432/postgres
depends_on:
- postgres
networks:
- prisma-network
networks:
prisma-network:
name: prisma-network This tutorial has been tested on Docker version We define the Linux Alpine (
|
We may remove these fixes in future and allow developers to resolve these issues themselves through custom docker files. For now though, they have no impact on projects that aren't running prisma. Related issues can be found here: - prisma/docs#4365 - prisma/prisma#16901 (comment)
Setting up Prisma on Docker environments is non-trivial, as plenty of comments in our Github issues demonstrate.
We should prepare a tutorial page that describes step-by-step how to use Prisma in the most popular Docker images, both for deploying serverless services (e.g., via AWS Fargate + AWS ECS) and for local development.
We should also take system architecture differences between the users host machine and their runtime machine into account (e.g., macOS users with Silicon CPUs won't be able to use
alpine
-based images locally unless they useDocker Buildx
with--platform="linux/amd64"
, as Prisma doesn't work on Alpine on arm64: prisma/prisma#8478)We should target the following system scenarios, inspired from our ecosystem-tests:
node:lts-alpine3.17
(and variants, likenode:lts-alpine
,node:alpine
) onamd64
andarm64
node:16-slim
(and variants, likenode:lts-buster-slim
) onamd64
and onarm64
gcr.io/distroless/nodejs18-debian11
onamd64
Opinable, these were mainly relevant when
prisma
didn't supportopenssl
3 or for users with weird linuxbrew/snap setups, which are arguably not generally used for serverless and local development on Docker:ubuntu:20.04
onamd64
ubuntu:22.04
onamd64
We should show our users how to:
docker-compose.yaml
, whose URL one can configure when building the Docker image)prisma db push
For constrained, barebone environments (such as
gcr.io/distroless
images and actual serverless services) we should tell users to write multi-stage Dockerfiles and only deploy the Prisma Client, delegating commands likeprisma db push
andprisma generate
to a previous docker stage.On Linux Alpine we should tell users not to install
libc
.Motivating issues
libz.so.1
) when using distroless Docker images prisma#16205libssl.so.1.1
: cannot open shared object file prisma#15505TODOs
libc6-compat
on Alpine foramd64
breaks anything with PrismaThe text was updated successfully, but these errors were encountered: