-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat: document how to run postgres in docker #266
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
## Setting up Docker | ||
|
||
Bison includes a `docker-compose.yml`, `Dockerfile` and `.dockerignore` | ||
|
||
The configuration is to run a postgres database locally. | ||
|
||
If you are interested in running the entire app, please see the examples below. | ||
|
||
## Running the Database | ||
|
||
To run postgres with docker, please add the following information to your `env` & `env.local` file. | ||
``` | ||
DATABASE_URL="postgresql://dev:dev@localhost:5432/dev?schema=public" | ||
``` | ||
Run `docker-compose up -d` in your terminal. If you prefer not to run in detached mode, you can remove the `-d` flag. | ||
|
||
To shut down docker, run `docker-compose down` | ||
|
||
## Using NextJS & Postgres with Docker | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to be consistent with Next's official name, it's |
||
|
||
The following configuration will help you run NextJS & Postgres. | ||
|
||
Make sure `@prisma/client` is on version: `3.13.0`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this needs to be on version 3.13.0? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will eliminate this. I was writing this when working on The error was related to running When following NextJS docs they are using node:alpine (https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile). Running Prisma and alpine has some issues and upgrading made it work: |
||
|
||
Dockerfile | ||
```Dockerfile | ||
FROM node:lts | ||
WORKDIR /usr/src/app | ||
|
||
COPY package.json yarn.lock ./ | ||
RUN yarn install | ||
|
||
COPY . . | ||
|
||
EXPOSE 3000 | ||
|
||
CMD ["yarn", "dev"] | ||
``` | ||
|
||
Add this to your services in `docker-compose.yml` file: | ||
```docker | ||
services: | ||
nextjs: | ||
build: | ||
context: ./ | ||
command: bash -c "yarn db:migrate && yarn db:seed && yarn dev" | ||
container_name: nextjs | ||
ports: | ||
- '3000:3000' | ||
volumes: | ||
- .:/app | ||
- /app/node_modules | ||
``` | ||
|
||
Change your database URL in your `env.local` to: | ||
``` | ||
DATABASE_URL="postgres://dev:dev@postgres/dev?schema=public" | ||
``` | ||
|
||
Somtimes your NextJs will not run due to postgres still booting up. You can add `connect_timeout=300` to the database URL. If you continue to have issues, you can press the `start` button in the docker application. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be a problem if you use |
||
|
||
To run NextJs with Prisma, it is best to use `node:lts`. There are current issues with running NextJs and Prisma using `node:alpine` | ||
|
||
Run `docker-compose up -d` | ||
Run `docker-compose down` to shut down. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
/.data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any more folders that should be added here? Basically you'd want to exclude anything that isn't needed to run the app (e.g. tests). Ideally all of the app code would be in one folder (e.g. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Default configuration to run your NextJs app locally: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to use a |
||
|
||
# FROM node:lts | ||
|
||
# WORKDIR /usr/src/app | ||
|
||
# COPY package.json yarn.lock ./ | ||
# # COPY prisma ./prisma/ | ||
# RUN yarn install | ||
|
||
# COPY . . | ||
|
||
# EXPOSE 3000 | ||
|
||
# CMD ["yarn", "dev"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: '3.8' | ||
|
||
services: | ||
postgres: | ||
container_name: postgres | ||
ports: | ||
- 5432:5432 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we should change the port. If the user is running a local version of Postgres, this would fail. |
||
image: postgres:14 | ||
environment: | ||
POSTGRES_USER: dev | ||
POSTGRES_PASSWORD: dev | ||
POSTGRES_DB: dev | ||
restart: always | ||
volumes: | ||
- ./.data/postgres:/var/lib/postgresql/data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...your
.env
and.env.local
file