0

Quite recently I have found many websites proposing solution to encapsulate a NPM and NGINX into a single dockerfile using so-called: "multi-stages" docker.


# first stage builds vue 
FROM mhart/alpine-node:12 as build-stage
WORKDIR /app
COPY . .
RUN npm ci 
RUN npm run build 

# second stage copies only the static dist files to nginx html dir
FROM nginx:stable-alpine as production-stage
VOLUME /var/log/nginx
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]

But it's not clear to me. After all, docker should host only one process, while in the examples in question it runs the NPM server and separately NGINX - am I reading these instructions in the Dockerfile correctly?

Isn't it more reasonable to take a "side-car" approach when hosting this on a service like Kubernetes or AWS ECS?

Michael
  • 129
  • 2
  • 10

1 Answers1

1

When the below line of code runs

COPY --from=build-stage /app/dist /usr/share/nginx/html

You are just copying the compiled JS/HTML and then hosting it via nginx. So there is are no trwo processes here. When you run npm start it run a dev server normally, which you don't need to run for production builds.

Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
  • Thanks a lot for that @tarun-lalwani!. Got it... now it makes much more sense... but can I still ask for something to clarify? I was never good at front-end languages, so forgive me but... I was considering Vue as not just typical JS, but a framework that has to be rendered also on the server-side, right? So if it's enough just to "build" artifacts that are HTML + JS and then just clear Nginx can handle that, without anything specific on node side (npm start?) then... if my assumption is correct? – Michael Mar 14 '22 at 20:44