gpt4 book ai didi

linux - Docker RUN groupadd && useradd 指令无效

转载 作者:IT王子 更新时间:2023-10-29 00:44:26 26 4
gpt4 key购买 nike

我已经使用 Dockerfile 构建了我的 Docker nginx“基础”镜像,其片段如下:

FROM ubuntu:14.04
MAINTAINER Me <me.net>
RUN apt-get update && apt-get install -y supervisor
ADD supervisord.conf /etc/supervisor/conf.d/
RUN apt-get install -y nginx
..

此图像随后与数据库容器和数据量相关联。后来,我想向容器中添加一个用户,以便我可以以该用户身份运行应用程序,因此我向 Dockerfile 添加了“RUN groupadd -r luqo33 && useradd -r -g luqo33 luqo33”指令,这样我的 Dockerfile 将如下所示:

FROM ubuntu:14.04
MAINTAINER Me <me.net>

RUN groupadd -r luqo33 && useradd -r -g luqo33 luqo33

RUN apt-get update && apt-get install -y supervisor
ADD supervisord.conf /etc/supervisor/conf.d/
RUN apt-get install -y nginx
..

然后我用 docker build -rm . 重新构建一个图像,然后用 docker-compose up 再次运行整个堆栈(我在 docker-撰写.yml)。

不幸的是,虽然 RUN groupadd -r luqo33 && useradd -r -g luqo33 luqo33 这一步没有出错,但是当我进入正在运行的 nginx 容器的 shell 时,luqo33 用户或 luqo33 组不存在。然后,我从 shell 中执行了相同的命令 (groupadd -r luqo33 && useradd -r -g luqo33 luqo33),并按预期添加了组和用户。

为什么 Dockerfile 中的 RUN groupadd -r luqo33 && useradd -r -g luqo33 luqo33 不会在重建时将用户和组添加到新容器中?我还尝试了具有相同效果(或没有效果)的 docker build --no-cache . 。我在这里缺少什么?

最佳答案

要确保您的构建命令没有使用任何缓存层,请使用 --no-cache选项。

docker build --no-cache .

如果你想要与 docker-compose 相同:

docker-compose build --no-cache

此外,由于您正在使用 docker-compose 启动容器,请确保运行 docker-compose rm 否则 docker-compose 将重用之前构建的图像。

关于linux - Docker RUN groupadd && useradd 指令无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30605964/

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