Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Installing PayloadCMS v3 on Coolify with Dockerfile Guide

default discord avatar
rfkuster4 months ago
3

Yup. I understand why its not set in the template. But with a tut specifically for a dockerfile deploy it would be good to know (ts/next noob here, c# dev for years but ts is just so incredilby flaky in so many ways, an too much different ways to solve stuff)

  • default discord avatar
    ritsu04555 months ago
    @408752101922045952

    It's expected to set it manually, we don't know will you use docker or not.

  • default discord avatar
    rfkuster5 months ago

    with the default payload 3.0 beta website template the next.config.js is missing the output: 'standalone' for this to work

  • discord user avatar
    seanzubrickas
    8 months ago

    Thanks to

    @783838279580909578

    for the tutorial above! Here's some additional help for anyone deploying on Coolify



    https://www.youtube.com/watch?v=Mvg624g_5zY

    ⚙️ Adjust the .env File

    Make sure to change your future server URL in the .env file. Otherwise, you won't be able to upload media.




    🚀 Start Local Payload v3 Server
    pnpm run dev


    🌐 Upload to Coolify via Dockerfile

    Upload the Dockerfile to Coolify, start it, create a user, and enjoy!



    Good luck and enjoy your new PayloadCMS v3 setup! 🎉🚀

    🐋 Dockerfile

    Explanation:



    This Dockerfile creates a multi-stage image for a Next.js application. It starts with a base Node.js image and installs dependencies. Then it builds the application and finally sets it up for a production environment.



    Dockerfile:



    # Base image with Node.js
    FROM node:20-alpine AS base
    
    # Install dependencies
    FROM base AS deps
    RUN apk add --no-cache libc6-compat
    WORKDIR /app
    
    # Copy package manager files and install dependencies
    COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
    RUN \
        if [ -f pnpm-lock.yaml ]; then \
        corepack enable pnpm && pnpm i --frozen-lockfile; \
        else \
        echo "Lockfile not found." && exit 1; \
        fi
    
    # Build the Next.js application
    FROM base AS builder
    WORKDIR /app
    COPY --from=deps /app/node_modules ./node_modules
    COPY . .
    ENV NEXT_TELEMETRY_DISABLED 1
    RUN \
        if [ -f pnpm-lock.yaml ]; then \
        corepack enable pnpm && pnpm run build; \
        else \
        echo "Lockfile not found." && exit 1; \
        fi
    
    # Final stage: Set up the runtime environment
    FROM base AS runner
    WORKDIR /app
    ENV NODE_ENV production
    ENV NEXT_TELEMETRY_DISABLED 1
    
    # Create and set the application user
    RUN addgroup --system --gid 1001 nodejs
    RUN adduser --system --uid 1001 nextjs
    
    # Copy the built files from the builder stage
    COPY --from=builder /app/public ./public
    # Change ownership of the public directory to the application user
    RUN chown -R nextjs:nodejs ./public
    
    # Setup directories and permissions for runtime
    RUN mkdir .next
    RUN chown nextjs:nodejs .next
    COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
    COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
    
    # Switch to non-root user
    USER nextjs
    
    # Expose the port the app runs on
    EXPOSE 3000
    ENV PORT 3000
    
    # Command to run the application
    CMD HOSTNAME="0.0.0.0" node server.js


    1️⃣

    Install the Latest Beta Version
    npx create-payload-app@beta


    2️⃣ Install pnpm 9 and the Latest Version of TypeScript

    # Install pnpm
    npm install -g pnpm
    
    # Install the latest TypeScript version
    pnpm add -D typescript


    3️⃣ Run pnpm install
    pnpm install
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.