Next.js Discord

Discord Forum

Docker not working on next production build

Answered
Cimarrón Uruguayo posted this in #help-forum
Open in Discord
Cimarrón UruguayoOP
See images... Not sure what's the issue
Answered by Ray
change ENV HOSTNAME localhost to ENV HOSTNAME "0.0.0.0"
View full answer

23 Replies

@Cimarrón Uruguayo See images... Not sure what's the issue
could you show the dockerfile or docker-compose.yaml?
@Ray could you show the dockerfile or docker-compose.yaml?
Cimarrón UruguayoOP
ah sorry, yes
FROM node:18-alpine AS base

# 1. Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat

WORKDIR /app

# Install dependencies
COPY package.json package-lock.json ./
RUN npm ci


# 2. Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
COPY .env.local .env.production
RUN npm run build


# 3. Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

COPY --from=builder /app/public ./public

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
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
ENV HOSTNAME localhost

CMD ["node", "server.js"]
version: "3"

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "3000:3000"
@Cimarrón Uruguayo yml version: "3" services: app: build: context: . dockerfile: Dockerfile ports: - "3000:3000"
version: "3"

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 3000:3000

try this
Cimarrón UruguayoOP
still nothing
could you show your next.config.js too
Cimarrón UruguayoOP
/** @type {import('next').NextConfig} */
const nextConfig = {
  output: "standalone"
}

module.exports = nextConfig
Cimarrón UruguayoOP
type docker logs 16
Cimarrón UruguayoOP
Answer
Cimarrón UruguayoOP
i swear if that's the bug 💀
how did you know about this? just curious
@Ray by here
Cimarrón UruguayoOP
but isn't port 3000 exposed outside the container
yea but look like the server was listening on localhost(docker container) only
Cimarrón UruguayoOP
bruh 💀
on canary its 0.0.0.0
anyways ill rebuild and give this a shot
@Ray yea but look like the server was listening on localhost(docker container) only
Cimarrón UruguayoOP
ok thank you for the solution :)