Mar*_*ry1 8 mount docker dockerfile
在构建期间,我想将文件从图像(从文件夹/opt/myApp/myFile.xml)复制到我的主机文件夹/opt/temp
在 Dockerfile 中,我使用 --mount 如下,尝试安装到我的本地测试文件夹:
RUN --mount=target=/opt/temp,type=bind,source=test cp /opt/myApp/myFile.xml /opt/temp
我成功构建了图像,但本地test文件夹是空的,有什么想法吗?
不支持在构建时将文件从映像复制到主机。
\n这可以在运行时使用卷轻松实现。
但是,如果您确实想通过各种方式解决此问题,您可以查看自定义构建输出文档,该文档引入了对此类活动的支持。
\n
这是一个受官方文档启发的简单示例:
\nDockerfile
FROM alpine AS stage-a\nRUN mkdir -p /opt/temp/\nRUN touch /opt/temp/file-created-at-build-time\nRUN echo "Content added at build-time" > /opt/temp/file-created-at-build-time\n\nFROM scratch as custom-exporter\nCOPY --from=stage-a /opt/temp/file-created-at-build-time .\nRun Code Online (Sandbox Code Playgroud)\n为此,您需要使用以下参数启动构建命令:
\nDOCKER_BUILDKIT=1 docker build --output out .\nRun Code Online (Sandbox Code Playgroud)\n这将在您的主机上除了 Dockerfile 之外创建一个out包含您需要的文件的目录:
.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Dockerfile\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 out\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 file-created-at-build-time\nRun Code Online (Sandbox Code Playgroud)\ncat out/file-created-at-build-time \nContent added at build-time\n\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
6603 次 |
| 最近记录: |