Issue in my multi stage dockerfile : not able find index.html file

My Dockerfile

# 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

[sshariff@localhost partners]$ docker build --target build -t build_output -f Dockerfile_Partners .

and

[sshariff@localhost partners]$ docker run --rm build_output ls /myapp/build
asset-manifest.json
assets
favicon.ico
index.html
logo192.png
logo512.png
manifest.json
robots.txt
static

it shows index.html is present, but why it is not identifying index.html when i run multi stage container?

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?

could you help me provide the full CMD COMMAND?

i tried adding this

# 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

You’ll have to wait until someone comes around who uses node and knows the serve application.

For troubleshooting, you could run and list the folder content:

docker run -ti --rm test ls -lR

Then check if the folder structure is indeed what you expect.

It got solved just by changing CMD

CMD [“serve”, “-s”, “.”, “-l”, “5124”]