gpt4 book ai didi

windows - 当涉及文件权限时,是否可以在Windows上构建相同的Linux docker镜像?

转载 作者:行者123 更新时间:2023-12-02 20:09:07 24 4
gpt4 key购买 nike

让我们有一个Dockerfile,它正在向Linux镜像添加一些大文件:

FROM busybox
ADD some_really_large_file /

我想在Windows上构建此图像,我需要该文件具有一些特定的文件权限,例如: -rw-------( 600)。

是否可以在Windows上构建此类图像而无需 RUN chmod命令,这会使图像大小增加一倍?

我的问题也可以理解为:我可以解决docker安全警告:

SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have -rwxr-xr-x permissions. It is recommended to double check and reset permissions for sensitive files and directories.



例如,可能以某种方式用于此任务的 Windows Subsystem for Linux

最佳答案

以下问题帮助我使用 GNU tar (例如Windows Subsystem for Linux内部)找到了一种解决方案:

  • File ownership on building docker images

  • 首先,使用 -p选项“压缩”数据以保留权限,并使用 --mode设置所需的权限:
    tar -czvpf some_really_large_file.tar.gz --mode='a-rwx,u+rw' some_really_large_file

    其次,由于 ADD会自动解压缩,因此请使用归档文件而不是Dockerfile中的原始文件:
    FROM busybox
    ADD some_really_large_file.tar.gz /

    关于windows - 当涉及文件权限时,是否可以在Windows上构建相同的Linux docker镜像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47788545/

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