@@ -19,8 +19,28 @@ FROM base AS builder
1919WORKDIR /app
2020COPY --from=deps /app/node_modules ./node_modules
2121COPY . .
22- # This will do the trick, use the corresponding env file for each environment.
23- COPY .env .env
22+
23+ # Receive the build args from docker-compose.yaml
24+ ARG NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL
25+ ARG NEXT_PUBLIC_BACKEND_SERVICE_HOST
26+ ARG NEXT_PUBLIC_BACKEND_SERVICE_PORT
27+ ARG NEXT_PUBLIC_BACKEND_API_VERSION
28+ ARG FRONTEND_SERVICE_INTERFACE
29+ ARG FRONTEND_SERVICE_PORT
30+
31+ # And convert them to environment variables for runtime
32+ ENV NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=$NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL
33+ ENV NEXT_PUBLIC_BACKEND_SERVICE_HOST=$NEXT_PUBLIC_BACKEND_SERVICE_HOST
34+ ENV NEXT_PUBLIC_BACKEND_SERVICE_PORT=$NEXT_PUBLIC_BACKEND_SERVICE_PORT
35+ ENV NEXT_PUBLIC_BACKEND_API_VERSION=$NEXT_PUBLIC_BACKEND_API_VERSION
36+
37+ RUN echo "NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL: ${NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL}"
38+ RUN echo "NEXT_PUBLIC_BACKEND_SERVICE_HOST: ${NEXT_PUBLIC_BACKEND_SERVICE_HOST}"
39+ RUN echo "NEXT_PUBLIC_BACKEND_SERVICE_HOST: ${NEXT_PUBLIC_BACKEND_SERVICE_PORT}"
40+ RUN echo "NEXT_PUBLIC_BACKEND_SERVICE_HOST: ${NEXT_PUBLIC_BACKEND_API_VERSION}"
41+ RUN echo "FRONTEND_SERVICE_INTERFACE: ${FRONTEND_SERVICE_INTERFACE}}"
42+ RUN echo "FRONTEND_SERVICE_PORT: ${FRONTEND_SERVICE_PORT}}"
43+
2444RUN npm run build
2545
2646# 3. Production image, copy all the files and run next
@@ -44,11 +64,10 @@ COPY --from=builder /app/package.json ./
4464USER nextjs
4565
4666# Expose the port Next.js runs on
47- EXPOSE 3000
67+ EXPOSE $FRONTEND_SERVICE_PORT
4868
49- ENV PORT=3000
50- ENV HOSTNAME=0.0.0.0
69+ ENV HOSTNAME=$FRONTEND_SERVICE_INTERFACE
70+ ENV PORT=$FRONTEND_SERVICE_PORT
5171
5272# Run the app using JSON array notation
5373CMD ["node" , "server.js" ]
54- # CMD HOSTNAME="0.0.0.0" node server.js
0 commit comments