Created
December 25, 2025 13:21
-
-
Save sametcn99/f05491e6c300bc5c073fb7382b721097 to your computer and use it in GitHub Desktop.
Docker configuration files to run PayloadCMS using the Bun runtime and PostgreSQL database.
This file contains hidden or 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
| version: '3' | |
| services: | |
| payload: | |
| image: oven/bun:1.1.14-alpine | |
| ports: | |
| - '3000:3000' | |
| volumes: | |
| - .:/home/bun/app | |
| - node_modules:/home/bun/app/node_modules | |
| working_dir: /home/bun/app/ | |
| command: sh -c "bun install --frozen-lockfile && bun run dev" | |
| depends_on: | |
| - postgres | |
| env_file: | |
| - .env | |
| environment: | |
| DATABASE_URL: postgres://payload:payload@postgres:5432/payload | |
| postgres: | |
| image: postgres:16-alpine | |
| ports: | |
| - '5432:5432' | |
| environment: | |
| POSTGRES_DB: payload | |
| POSTGRES_USER: payload | |
| POSTGRES_PASSWORD: payload | |
| volumes: | |
| - postgres_data:/var/lib/postgresql/data | |
| volumes: | |
| node_modules: | |
| postgres_data: |
This file contains hidden or 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
| # To use this Dockerfile, you have to set `output: 'standalone'` in your next.config.js file. | |
| FROM oven/bun:alpine AS base | |
| WORKDIR /app | |
| # Install dependencies only when needed | |
| FROM base AS deps | |
| RUN apk add --no-cache libc6-compat | |
| WORKDIR /app | |
| # Install dependencies with Bun, respecting existing lockfiles when present | |
| COPY package.json bun.lockb* yarn.lock* package-lock.json* pnpm-lock.yaml* ./ | |
| RUN \ | |
| if [ -f bun.lockb ] || [ -f yarn.lock ] || [ -f package-lock.json ] || [ -f pnpm-lock.yaml ]; then \ | |
| bun install --frozen-lockfile; \ | |
| else \ | |
| bun install; \ | |
| fi | |
| # Rebuild the source code only when needed | |
| FROM base AS builder | |
| WORKDIR /app | |
| COPY --from=deps /app/node_modules ./node_modules | |
| COPY . . | |
| # Next.js collects completely anonymous telemetry data about general usage. | |
| # Learn more here: https://nextjs.org/telemetry | |
| # ENV NEXT_TELEMETRY_DISABLED 1 | |
| RUN bun run build | |
| # Production image, copy all the files and run next | |
| FROM base AS runner | |
| WORKDIR /app | |
| ENV NODE_ENV production | |
| ENV PORT 3000 | |
| RUN addgroup -S bunuser && adduser -S bun -G bunuser | |
| COPY --from=builder /app/public ./public | |
| # Prepare prerender cache with correct permissions | |
| RUN mkdir -p .next && chown bun:bunuser .next | |
| COPY --from=builder --chown=bun:bunuser /app/.next/standalone ./ | |
| COPY --from=builder --chown=bun:bunuser /app/.next/static ./.next/static | |
| USER bun | |
| EXPOSE 3000 | |
| # server.js is created by next build from the standalone output | |
| CMD HOSTNAME="0.0.0.0" bun --bun server.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment