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

Is ti possible to build the same linux docker image on windows when file permissions involved?

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

FROM busybox
ADD some_really_large_file /

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

是否可以在 windows 上构建这样的图像而无需 RUN chmod 命令,这会使图像大小加倍?

我的问题也可以理解为:Can I fix the docker security warning:

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

首先,"tar" 您的数据使用 -p 选项保留权限并 --mode 设置所需权限:

tar -czvpf some_really_large_file.tar.gz --mode='a-rwx,u+rw' some_really_large_file

其次,因为ADD untars automagically,使用存档而不是Dockerfile中的原始文件:

FROM busybox
ADD some_really_large_file.tar.gz /