Skip to content

Commit e3d6ef1

Browse files
authored
fix #7: use Docker service name backend:8000 instead of localhost in Dockerfile ENV
1 parent 540893d commit e3d6ef1

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

frontend/Dockerfile

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ COPY . .
1818

1919
# Environment variables for build
2020
ENV NEXT_TELEMETRY_DISABLED 1
21-
ENV NEXT_PUBLIC_API_URL=http://localhost:8000
21+
# Fix #7: Use Docker service name 'backend' instead of localhost
22+
# 'localhost' does not resolve to the backend container at build time
23+
ENV NEXT_PUBLIC_API_URL=http://backend:8000
2224

2325
# Build the application
2426
RUN npm run build
@@ -30,27 +32,17 @@ WORKDIR /app
3032
ENV NODE_ENV production
3133
ENV NEXT_TELEMETRY_DISABLED 1
3234

33-
# Create a non-root user
35+
# Create non-root user for security
3436
RUN addgroup --system --gid 1001 nodejs
3537
RUN adduser --system --uid 1001 nextjs
3638

37-
# Copy built application
3839
COPY --from=builder /app/public ./public
3940
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
4041
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
4142

42-
# Switch to non-root user
4343
USER nextjs
4444

45-
# Expose port
4645
EXPOSE 3000
47-
4846
ENV PORT 3000
49-
ENV HOSTNAME "0.0.0.0"
50-
51-
# Health check
52-
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
53-
CMD node -e "require('http').get('http://localhost:3000', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
5447

55-
# Run the application
5648
CMD ["node", "server.js"]

0 commit comments

Comments
 (0)