Fix: Replace invalid COPY commands inside RUN with proper multi-stage copy instructions

The RUN instruction cannot contain COPY commands. Fixed by moving the COPY
instructions outside the RUN block and copying both Next.js (.next) and
Vite (dist) build outputs from the builder stage. The nginx configuration
can serve both build outputs appropriately.

Fixes: Docker build failure with "COPY: not found" error
This commit is contained in:
Stephanos A.
2026-06-02 23:33:56 +03:00
parent 0b02944180
commit c3d7803bd5

View File

@@ -53,13 +53,10 @@ FROM nginx:alpine AS runner
ARG APP_PATH
COPY infrastructure/nginx/spa.conf /etc/nginx/conf.d/default.conf
# Copy Next.js build output if it exists
RUN if [ -d "/app/${APP_PATH}/.next" ]; then \
COPY --from=builder /app/${APP_PATH}/.next /usr/share/nginx/html/.next && \
COPY --from=builder /app/${APP_PATH}/public /usr/share/nginx/html/public 2>/dev/null || true; \
else \
COPY --from=builder /app/${APP_PATH}/dist /usr/share/nginx/html; \
fi
# Copy Next.js or Vite build output from builder stage
COPY --from=builder /app/${APP_PATH}/.next /usr/share/nginx/html/.next
COPY --from=builder /app/${APP_PATH}/public /usr/share/nginx/html/public
COPY --from=builder /app/${APP_PATH}/dist /usr/share/nginx/html/dist
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]