Reputation: 47
I am new to Docker, I have a React.js app with the build forder (npm run build
), I want to dockerize my app to make a container.
I made a Dockerfile with this config:
FROM node:12-alpine
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD [ "npm", "start" ]
I got those images : dockerimages.
Can I dockerize only the build path which is 20MB or the image size is normal?
Upvotes: 1
Views: 986
Reputation: 2322
Yes, you can achieve this using multistage Dockerfile, I'm using this for VueJS and Angular.
Bonus: you can use NGINX for proxying your requests to your app.
NGINX config and .dockerignore files can be found here.
##### 01- Build app
FROM node:lts-alpine as node
LABEL author="Waqas Dilawar"
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . .
RUN npm run build
##### 02- Run NGINX using build from step 01
FROM nginx:alpine
VOLUME /var/cache/nginx
COPY --from=node /app/dist /usr/share/nginx/html
COPY ./config/nginx.conf /etc/nginx/conf.d/default.conf
Upvotes: 3