-
-
Save alyahmady/bbbcf4dc968b86654c7358bfcb32d205 to your computer and use it in GitHub Desktop.
Caddy + Next.js + Docker build
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
| DOMAIN=http//:localhost | |
| # For production, use a real domain without scheme (http:// or https://) to be served with auto-renewal HTTPS/SSL | |
| # DOMAIN=example.com |
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
| FROM node:21.7.1-alpine3.19 AS base | |
| FROM base AS deps | |
| RUN apk add --no-cache libc6-compat | |
| WORKDIR /app | |
| COPY package.json package-lock.json ./ | |
| RUN npm ci | |
| FROM base AS builder | |
| WORKDIR /app | |
| COPY --from=deps /app/node_modules ./node_modules | |
| COPY public ./public | |
| COPY src ./src | |
| COPY next.config.mjs ./next.config.mjs | |
| COPY package.json ./package.json | |
| COPY package-lock.json ./package-lock.json | |
| COPY postcss.config.js ./postcss.config.js | |
| COPY tailwind.config.ts ./tailwind.config.ts | |
| COPY tsconfig.json ./tsconfig.json | |
| # You can simply replace all above COPY commands with below command for your own project | |
| # COPY . . | |
| ENV NEXT_TELEMETRY_DISABLED 1 | |
| RUN npm run build | |
| FROM base AS runner | |
| WORKDIR /app | |
| ENV NODE_ENV production | |
| ENV NEXT_TELEMETRY_DISABLED 1 | |
| RUN addgroup --system --gid 1001 nodejs | |
| RUN adduser --system --uid 1001 nextjs | |
| COPY --from=builder /app/public ./public | |
| COPY package.json ./package.json | |
| RUN mkdir -p /app/.next | |
| RUN chown nextjs:nodejs /app/.next | |
| COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ | |
| COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static | |
| USER nextjs | |
| EXPOSE 3000 | |
| ENV PORT 3000 | |
| CMD HOSTNAME="0.0.0.0" node server.js |
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
| FROM caddy/caddy:2.7.6-alpine | |
| COPY Caddyfile /etc/caddy/Caddyfile | |
| CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"] |
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
| {$DOMAIN} { | |
| handle { | |
| reverse_proxy landing:3000 | |
| } | |
| } |
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
| services: | |
| app: | |
| restart: always | |
| container_name: landing_app | |
| hostname: landing # underscore make it invalid (RFC 1034/1035) | |
| build: | |
| context: ./ | |
| dockerfile: app.dockerfile | |
| env_file: | |
| - .env | |
| expose: | |
| - 3000 | |
| logging: | |
| driver: "json-file" | |
| options: | |
| max-size: "100m" | |
| max-file: "5" | |
| caddy: | |
| container_name: caddy | |
| hostname: caddy | |
| restart: unless-stopped | |
| build: | |
| context: ./ | |
| dockerfile: caddy.dockerfile | |
| depends_on: | |
| - "app" | |
| volumes: | |
| - ./data/caddy_data:/data | |
| - ./data/caddy_config:/config | |
| env_file: | |
| - .env | |
| ports: | |
| - "80:80" | |
| - "443:443" | |
| logging: | |
| driver: "json-file" | |
| options: | |
| max-size: "100m" | |
| max-file: "5" |
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
| /** @type {import('next').NextConfig} */ | |
| const nextConfig = { | |
| reactStrictMode: false, | |
| output: "standalone", | |
| }; | |
| export default nextConfig; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment