最近,我發現許多網站提出了使用所謂的“多階段”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”方法不是更合理嗎?
uj5u.com熱心網友回復:
當下面的代碼行運行時
COPY --from=build-stage /app/dist /usr/share/nginx/html
您只是復制已編譯的 JS/HTML,然后通過nginx. 所以這里沒有 trwo 行程。當你運行npm start它時,它會正常運行一個開發服務器,你不需要為生產構建運行它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/444639.html
上一篇:記憶體不足:殺死行程
