I'm a little new to Docker and trying to wrap my head around some of the concepts.
In a lot of tutorials and articles (actually, almost all of them), this is a typical Dockerfile for a create-react-app and nginx configuration:
# CRA
FROM node:alpine as build-deps
WORKDIR /usr/src/app
COPY package.json package-lock.json ./
RUN npm install
COPY . ./
RUN npm run build
# Nginx
FROM nginx:1.12-alpine
COPY --from=build-deps /usr/src/app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Assuming everything works as expected, the image would be huge.
I had the idea of taking a slightly different approach. Run npm install && npm run build locally, and then have this as the Dockerfile:
FROM nginx:1.12-alpine
WORKDIR /opt/app-root
COPY ./nginx/nginx.conf /etc/nginx/
COPY ./build ./src/dist/
COPY ./node_modules .
USER 1001
EXPOSE 8080
ENTRYPOINT ["nginx", "-g", "daemon off;"]
Which approach is better? Whenever I run docker build -t app-test:0.0.1 ., it seems to me that the second approach is always faster.