# Stage 1: Build
FROM node:18-alpine AS build
WORKDIR /myapp
RUN apk --no-cache add curl
COPY package.json .
COPY package-lock.json .
RUN npm ci #install all dependencies
COPY . .
ENV NODE_OPTIONS=–max-old-space-size=2048
RUN npm run build
# STAGE 2: Production
FROM node:18-alpine AS production
WORKDIR /src/atsea
COPY --from=build /myapp/build .
COPY package.json package-lock.json .
RUN npm ci --only=production # Install only production dependencies
RUN npm install -g serve
CMD [“serve”, “-s”, “build”, “-l”, “5124”]
[sshariff@localhost partners]$ docker run --name testy -p 5124:5124 dev_partners
INFO Accepting connections at [http://localhost:5124](http://localhost:5124/)
HTTP 9/30/2024 6:19:57 PM 192.168.1.9 GET /
HTTP 9/30/2024 6:19:57 PM 192.168.1.9 Returned 404 in 22 ms
HTTP 9/30/2024 6:20:02 PM 192.168.1.9 GET /
HTTP 9/30/2024 6:20:02 PM 192.168.1.9 Returned 404 in 5 ms
HTTP 9/30/2024 6:20:03 PM 192.168.1.9 GET /
HTTP 9/30/2024 6:20:03 PM 192.168.1.9 Returned 404 in 2 ms
HTTP 9/30/2024 6:20:04 PM 192.168.1.9 GET /
HTTP 9/30/2024 6:20:04 PM 192.168.1.9 Returned 404 in 2 ms
this error must be because it is not able to find index.html under build directory, but when i checked individually by running commands
I fixed your formatting. Please edit your post and look how I used the backticks - you will see I removed almost all the backticks you used, and reduced them to ``` before and after each code block.
You run the CMD in the folder src/atsea. How should server a globally installed node application, know that you want it to serve container from /myapp/build, if you don’t specify it?
# Stage 1: Build
FROM node:18-alpine AS build
WORKDIR /myapp
RUN apk --no-cache add curl
COPY package.json .
COPY package-lock.json .
RUN npm ci #install all dependencies
COPY . .
ENV NODE_OPTIONS=--max-old-space-size=2048
RUN npm run build
FROM node:18-alpine AS production
WORKDIR /src/atsea
COPY --from=build /myapp/build .
COPY package.json package-lock.json .
RUN npm ci --only=production # Install only production dependencies
RUN npm install -g serve
CMD ["serve", "-s", "/src/atsea/build", "-l", "5124"]
But still the same error
[sshariff@localhost partners]$ docker run --name testy -p 5124:5124 partner_test
INFO Accepting connections at http://localhost:5124
HTTP 10/1/2024 7:14:59 AM 192.168.0.53 GET /
HTTP 10/1/2024 7:14:59 AM 192.168.0.53 Returned 404 in 20 ms
HTTP 10/1/2024 7:15:02 AM 192.168.0.53 GET /
HTTP 10/1/2024 7:15:02 AM 192.168.0.53 Returned 404 in 3 ms
HTTP 10/1/2024 7:15:15 AM 192.168.0.53 GET /
HTTP 10/1/2024 7:15:15 AM 192.168.0.53 Returned 404 in 2 ms