[SOLVED] Why is my Docker Image so large for AstroJS app?


This Content is from Stack Overflow. Question asked by RabidTunes

I’m working on a webpage built with Astrojs. I’m fairly newbie as a frontend developer, and definitely not a full expert in Docker, but my current working folder is 270MB in size, yet when i build the docker image it gets to 1.32GB

This is my DockerFile

FROM node:lts-alpine

ENV NODE_ENV=production
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]

RUN yarn install
COPY . .

RUN chown -R node /usr/src/app
USER node
CMD ["yarn", "run", "start", "--host"]

I’ve even used the alpine image for Node.js, but it still seems so large for me.
Do you know what might be the issue here?


I realized that, for my use case, I just wanted the output of astro build which is a bunch of static html files with some javascript on certain parts, since I don’t have server side rendering enabled.

I just changed completely the Dockerfile to the following and now it’s really small, only 9.81MB

# ---> Build stage
FROM node:18-bullseye as node-build

ENV NODE_ENV=production
WORKDIR /usr/src/app
COPY . /usr/src/app/
RUN yarn install --silent --production=true --frozen-lockfile
RUN yarn build --silent

# ---> Serve stage
FROM nginx:stable-alpine
COPY --from=node-build /usr/src/app/dist /usr/share/nginx/html

This Question was asked in StackOverflow by RabidTunes and Answered by RabidTunes It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?