Vue (NPM) +单个 docker 中的 NGINX
最近,我发现许多网站提出了使用所谓的“多阶段”docker 将 NPM 和 NGINX 封装到单个 dockerfile 中的解决方案。
# 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;"]
但我不清楚。毕竟,docker 应该只托管一个进程,而在相关示例中,它运行 NPM 服务器并单独运行 NGINX - 我是否正确阅读了 Dockerfile 中的这些说明?
当将其托管在 Kubernetes 或 AWS ECS 等服务上时,采用“side-car”方法不是更合理吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当下面的代码行运行时,
您只需复制编译后的 JS/HTML,然后通过
nginx
托管它。所以这里没有两个进程。当您运行npm start
时,它会正常运行开发服务器,您不需要为生产构建运行该服务器。When the below line of code runs
You are just copying the compiled JS/HTML and then hosting it via
nginx
. So there is are no trwo processes here. When you runnpm start
it run a dev server normally, which you don't need to run for production builds.