容器中的目录所有权:root vs mambauser

问题描述 投票:0回答:1

我们正在尝试将其中一张图像从使用 miniconda3 作为基础图像移动到 micromamba (1.5-bookworm-slim)。

我们的存储库包含一个 Makefile,其中包含用于构建映像并运行一些测试的命令。

构建没有什么特别的,Dockerfile 也是如此。 (我们简单地切换到

root
以使用 APT 安装软件包。micromamba 映像中的默认用户是
mambauser
。)

测试命令如下:

docker run --mount type=bind,source="$$(pwd)/test-data",target=/assets --mount type=bind,source="$$(pwd)/test-output",target="/tmp/test-output"  image_name:tag [call to script and arguments omitted]

这最终在我的 Ubuntu 系统上失败,因为脚本无法写入 /tmp/test-output 目录,因为它属于

root
。然而,当同事在他的 Mac 上运行它时,文件夹的所有者是
mambauser
并且测试运行成功。

当我明确地将

--user mambauser
添加到
run
命令时,所有者显示为
1000
,但测试仍然失败。

如果没有在 Dockerfile 中将用户设置为

root
或以
root
身份运行测试,有没有办法让它工作?

如果需要,很乐意分享 Dockerfile、系统设置等相关详细信息。

docker permissions root mamba micromamba
1个回答
0
投票

将当前用户的用户和组 ID(或名称)作为参数传递给

docker run
命令解决了该问题。

docker run -u "$(id -u):$(id -g)"

参考:https://github.com/mamba-org/micromamba-docker/discussions/382#discussioncomment-7495825

© www.soinside.com 2019 - 2024. All rights reserved.