Skip to content

Docker Compose

Prisma is compatible with a variety of databases. Below are Docker Compose snippets for setting up PostgreSQL and MySQL, allowing you to easily spin up a database environment for development.

Create a compose.yml and a .env file in your project root to store the Docker Compose configuration and environment variables.

Terminal window
# Docker compose configuration file
# you can name it compose.yml or docker-compose.yml
touch compose.yml
# add to .gitignore
touch .env

Copy PostgreSQL and MySQL configurations into the respective files as shown below. Start the docker containers using the command:

Terminal window
docker compose up -d
services:
postgres:
image: postgres:latest
container_name: postgres
restart: unless-stopped
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
ports:
- '5432:5432'
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}']
interval: 1s
timeout: 5s
retries: 10
volumes:
- postgres_data:/var/lib/postgresql
volumes:
postgres_data:
services:
mysql:
image: mysql:latest
container_name: mysql
restart: unless-stopped
ports:
- '3306:3306'
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-u", "root", "-p${MYSQL_ROOT_PASSWORD}"]
interval: 1s
timeout: 5s
retries: 10
volumes:
- mysql_data:/var/lib/mysql
volumes:
mysql_data: