-
Notifications
You must be signed in to change notification settings - Fork 797
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
35 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,15 @@ | |
title: "How to use Prisma in Docker" | ||
metaTitle: "How to use Prisma in Docker" | ||
description: "Learn step-by-step configure a Prisma ORM app in Docker" | ||
sidebar_label: "Docker" | ||
sidebar_label: 'Build Docker apps with Prisma ORM' | ||
image: "/img/guides/prisma-orm-docker.png" | ||
tags: | ||
- Docker | ||
- Alpine | ||
- Containerization | ||
--- | ||
|
||
This guide walks you through setting up a Prisma ORM application within a Docker environment. Youβll learn how to configure a Node.js project, integrate Prisma for database management, and orchestrate the application using Docker Compose. By the end, youβll have a fully functional Prisma application running in a Docker container. | ||
This guide walks you through setting up a Prisma ORM application within a Docker environment. You'll learn how to configure a Node.js project, integrate Prisma for database management, and orchestrate the application using Docker Compose. By the end, you'll have a fully functional Prisma application running in a Docker container. | ||
|
||
## Prerequisites | ||
|
||
|
@@ -35,7 +35,7 @@ docker ps -q | xargs docker stop | |
|
||
## 1. Set up your Node.js and Prisma application | ||
|
||
Letβs start by creating a simple Node.js application with Prisma ORM and [Express.js](https://expressjs.com/). | ||
Let's start by creating a simple Node.js application with Prisma ORM and [Express.js](https://expressjs.com/). | ||
|
||
### 1.1. Initialize your project | ||
|
||
|
@@ -117,7 +117,7 @@ In the `schema.prisma` file, we specify a [custom `output` path](/orm/prisma-cli | |
|
||
### 1.4. Create an Express.js server | ||
|
||
With the Prisma schema in place, letβs create an Express.js server to interact with the database. Start by creating an `index.js` file: | ||
With the Prisma schema in place, let's create an Express.js server to interact with the database. Start by creating an `index.js` file: | ||
|
||
```terminal | ||
touch index.js | ||
|
@@ -166,11 +166,11 @@ Update the `package.json` scripts to include commands for running the server and | |
} | ||
``` | ||
|
||
Now that the application is set up, letβs move on to configuring a PostgreSQL database using Docker Compose. | ||
Now that the application is set up, let's move on to configuring a PostgreSQL database using Docker Compose. | ||
|
||
## 2. Set up a PostgreSQL database with Docker Compose | ||
|
||
To perform database migrations, weβll create a standalone PostgreSQL database using Docker Compose. | ||
To perform database migrations, we'll create a standalone PostgreSQL database using Docker Compose. | ||
|
||
### 2.1. Create a Docker Compose file for PostgreSQL | ||
|
||
|
@@ -269,23 +269,23 @@ This command will: | |
- Remove the default network created by Docker Compose. | ||
- Remove associated volumes (if not named explicitly). | ||
|
||
Now that weβve tested the application locally, letβs containerize it using Docker. | ||
Now that we've tested the application locally, let's containerize it using Docker. | ||
|
||
## 3. Run the app and database together with Docker Compose | ||
|
||
Weβll now containerize the application using Docker, ensuring it can run in any environment. | ||
We'll now containerize the application using Docker, ensuring it can run in any environment. | ||
|
||
To do that create a `Dockerfile` in project root: | ||
|
||
```terminal | ||
touch Dockerfile | ||
``` | ||
|
||
For the next step, youβll need to choose between two options for the base image: `node:alpine` (lightweight) or `node:slim` (stable). Both options are fully supported by Prisma ORM, but may have to be configured differently. | ||
For the next step, you'll need to choose between two options for the base image: `node:alpine` (lightweight) or `node:slim` (stable). Both options are fully supported by Prisma ORM, but may have to be configured differently. | ||
|
||
### 3.1. Option 1: Use Linux Alpine (`node:alpine`) as a base image | ||
|
||
The node:alpine image is based on Alpine Linux, a lightweight Linux distribution that uses the `musl` C standard library. Itβs perfect if you want to keep your container small and efficient. Prisma supports Alpine on `amd64` out of the box, and supports it on `arm64` since `[email protected]`. | ||
The node:alpine image is based on Alpine Linux, a lightweight Linux distribution that uses the `musl` C standard library. It's perfect if you want to keep your container small and efficient. Prisma supports Alpine on `amd64` out of the box, and supports it on `arm64` since `[email protected]`. | ||
|
||
Add the following content to the `Dockerfile`: | ||
|
||
|
@@ -317,7 +317,7 @@ Related Docker images: | |
|
||
### 3.1. Option 2: Use Linux Debian (`node:slim`) as a base image | ||
|
||
The `node:slim` image is based on Linux Debian, a stable and widely supported distribution that uses the `glibc` C standard library. It is mostly supported out of the box on `amd64` and `arm64`, making it a good choice if youβre running into compatibility issues with Alpine or need a more production-ready environment. However, some older versions of this image may come without `libssl` installed, so itβs sometimes necessary to install it manually. | ||
The `node:slim` image is based on Linux Debian, a stable and widely supported distribution that uses the `glibc` C standard library. It is mostly supported out of the box on `amd64` and `arm64`, making it a good choice if you're running into compatibility issues with Alpine or need a more production-ready environment. However, some older versions of this image may come without `libssl` installed, so it's sometimes necessary to install it manually. | ||
|
||
Add the following content to the `Dockerfile`: | ||
|
||
|
@@ -347,7 +347,7 @@ Related Docker images: | |
|
||
### 3.2. Create and configure a Docker Compose file | ||
|
||
Now that the `Dockerfile` is ready, weβll use Docker Compose to manage both the app and the database together. This makes it easy to start, stop, and manage the entire setup. | ||
Now that the `Dockerfile` is ready, we'll use Docker Compose to manage both the app and the database together. This makes it easy to start, stop, and manage the entire setup. | ||
|
||
Create a `docker-compose.yml` file in your project folder: | ||
|
||
|
@@ -419,7 +419,7 @@ DATABASE_URL="postgresql://postgres:prisma@postgres_db:5432/postgres?schema=publ | |
|
||
### 3.4. Build and run the application | ||
|
||
With everything set up, itβs time to build and run the app using Docker Compose. Run the following command: | ||
With everything set up, it's time to build and run the app using Docker Compose. Run the following command: | ||
|
||
```terminal | ||
docker compose -f docker-compose.yml up --build -d | ||
|
@@ -433,7 +433,7 @@ No users have been added yet. | |
|
||
### 3.5. Bonus: Add Prisma Studio for database management | ||
|
||
[Prisma Studio](/orm/tools/prisma-studio) offers a graphical user interface (GUI) that allows you to view and manage your database directly in the browser. Itβs a great tool for debugging and managing your data during development. | ||
[Prisma Studio](/orm/tools/prisma-studio) offers a graphical user interface (GUI) that allows you to view and manage your database directly in the browser. It's a great tool for debugging and managing your data during development. | ||
|
||
To add Prisma Studio to your Docker setup, update the `docker-compose.yml` file: | ||
|
||
|
@@ -507,4 +507,4 @@ Run the following command to start everything: | |
docker compose -f docker-compose.yml up --build -d | ||
``` | ||
|
||
By following this guide, youβve successfully containerized your Prisma app and database using Docker Compose. | ||
By following this guide, you've successfully containerized your Prisma app and database using Docker Compose. |