Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

[bug] Implement Multi-Stage Build in Dockerfile #814

Closed
Saurav-Pant opened this issue Oct 18, 2023 · 9 comments · Fixed by #827
Closed

[bug] Implement Multi-Stage Build in Dockerfile #814

Saurav-Pant opened this issue Oct 18, 2023 · 9 comments · Fixed by #827
Assignees
Labels
bug Something isn't working

Comments

@Saurav-Pant
Copy link

Saurav-Pant commented Oct 18, 2023

Describe the bug

The current Dockerfile lacks a multi-stage build. Adding this enhancement significantly reduces the image size, optimizes distribution, and simplifies container management.

To Reproduce

Go to Dockerfile
and add this
COPY package*.json ./ before this line COPY . .

Expected Behavior

No response

Screenshot/ Video

No response

Additional context

No response

@Saurav-Pant Saurav-Pant added the bug Something isn't working label Oct 18, 2023
@github-actions
Copy link

Hey Hey! 👋🏻 Thank you so much for raising an issue. The maintainers will get back to you soon for discussion over the issue! In the meantime join our Discord server and checkout our YouTube channel.

@SaptarshiSarkar12
Copy link
Contributor

@AnuragThePathak Can I work on this issue?

@AnuragThePathak
Copy link
Contributor

@SaptarshiSarkar12 go ahead

@SaptarshiSarkar12
Copy link
Contributor

@AnuragThePathak Thank you for assigning this issue to me 😁

@SaptarshiSarkar12
Copy link
Contributor

@AnuragThePathak I have tried multiple approaches to add muti-stage docker build. But, craco start is not working without node_modules thereby increasing the size of the image. Please let me know how I should solve this problem.

My Dockerfile 👇

FROM node:17-alpine AS deps
COPY package.json ./
RUN npm install

FROM deps AS builder
COPY . .
RUN npm run build

FROM node:17-alpine AS runner
COPY --from=builder build ./build
RUN npm install -g serve
EXPOSE 3000
CMD ["serve", "-s", "build"]

The error 👇

> start
> craco start

sh: 1: craco: not found

@AnuragThePathak
Copy link
Contributor

@SaptarshiSarkar12 you should use package*.json then only package-lock.json will be copied

@SaptarshiSarkar12
Copy link
Contributor

@AnuragThePathak I was using npm install previously. So, if I use package-lock.json, then, I also need to change the command to npm ci, right?

@AnuragThePathak
Copy link
Contributor

Yes you must use npm ci else we may see unintended behaviors in production.

@SaptarshiSarkar12
Copy link
Contributor

@AnuragThePathak Okay. I have added. Please check #827

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants