gpt4 book ai didi

Docker 运行和体积说明

转载 作者:行者123 更新时间:2023-12-02 19:32:14 24 4
gpt4 key购买 nike

下面是我的 dockerfile,我在 copy 命令中复制 js 文件,然后设置工作目录,然后是卷和运行命令。下面是我的 dockerfile
1)我了解node_modules(由于运行npm install而创建)在容器首次初始化时被清除,因为在同一位置创建卷
我的问题是为什么我在步骤 3 中复制的 app.js 没有被删除,因为它也与卷在同一路径上?

FROM node:latest

ENV NODE_ENV=production
ENV PORT=3000

COPY . /app
WORKDIR /app
VOLUME ["/app"]


RUN npm install

EXPOSE $PORT

ENTRYPOINT ["node","app.js"]

最佳答案

问:为什么我的 app.js(我在步骤 3 中复制的)在 node_modules 时没有被清除是。
答:如卷部分下的 docker 文档中所述。
报价:

Changing the volume from within the Dockerfile:

If any build stepschange the data within the volume after it has been declared, thosechanges will be discarded.


引用: https://docs.docker.com/engine/reference/builder/#notes-about-specifying-volumes

关于Docker 运行和体积说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50222266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com