我的Dockerfile中有以下命令序列;请注意,使用sed替换的是
RUN sed -i "s/replace this/with that/g" ./dir/file.yaml
COPY ./dir/file.yaml /usr/src/app/node_modules/serve-swagger-editor/node_modules/swagger-editor/spec-files/这几乎运行良好,即将file.yaml复制到目标位置,但是:
./dir/file.yaml包含sed所做的更改,/usr/src/.../spec-files/file.yaml没有。事实证明,这一解决办法解决了复制问题:
RUN sed -i "s/replace this/with that/g" ./dir/file.yaml
RUN cp ./dir/file.yaml /usr/src/app/node_modules/serve-swagger-editor/node_modules/swagger-editor/spec-files/有人能解释一下这种奇怪的行为吗?
发布于 2016-04-13 06:24:03
RUN在容器中执行命令,因此sed被应用于容器中的文件./dir/file.yaml。您可能在WORKDIR/dir/file.yaml (沃克迪尔)中有一个/相同的文件,这解释了为什么第二个选项可以工作。
第一个版本中的COPY用主机构建目录中的./dir/file.yaml覆盖/usr/src/app/node_modules/serve-swagger-editor/node_modules/swagger-editor/spec-files/文件。因为它在容器之外,所以它以前没有受到sed命令的影响。
因此,您可以做的是首先在容器中COPY文件,然后使用RUN命令来修改它。或者在运行docker build之前修改它。
https://stackoverflow.com/questions/36589996
复制相似问题