我正在从提供的Docker镜像构建Docker镜像。我需要安装需要管理权限的新依赖项。提供的映像的默认用户没有管理权限。完成后,我想将默认用户改回以前的默认用户。
有没有一种方法可以在不事先知道的情况下通用地保留基本图像的用户?
注意:我并不是在问如何检查docker镜像并找到Dockerfile
之外的默认用户。我想知道是否有一种方法可以在文件中做到这一点。
请参阅下面的示例Dockerfile
FROM supliedImage
USER root
... Perform administrative task
USER <Default user from supplied image>
发布于 2020-10-30 01:26:30
好吧..。没有办法做到你想要的方式,但你总是可以使用多阶段构建的变通方法:
FROM solr:alpine as build
RUN whoami
FROM build as prepare_dependencies
USER root
RUN echo 'I am root' > /the_root_important_message
FROM build
COPY --from=prepare_dependencies /the_root_important_message /the_root_vital_message
RUN echo "now I'm $( whoami )"
RUN cat /the_root_vital_message
CMD echo 'this is a pain'
不知何故我很确定这不是你要找的..。
好吧,由于这个话题很有趣,我决定尝试一种不同的方法:
FROM solr:alpine as build
RUN whoami
FROM build as prepare_dependencies
USER root
RUN apk --no-cache --update add sudo \
&& echo 'ALL ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers
RUN echo "this is secret" > /secretfile
RUN chmod 400 /secretfile
FROM build
COPY --from=prepare_dependencies /usr/bin/sudo /usr/bin/sudo
COPY --from=prepare_dependencies /usr/lib/sudo /usr/lib/sudo
COPY --from=prepare_dependencies /etc/sudoers /etc/sudoers
COPY --from=prepare_dependencies /secretfile /secretfile
RUN sudo -l
RUN sudo cat /secretfile
RUN echo "now I'm $( whoami )"
RUN echo "cleanup" \
&& sudo rm -rf \
/etc/sudoers /secretfile \
/usr/lib/sudo /usr/bin/sudo
CMD echo 'this is a pain'
https://stackoverflow.com/questions/64592299
复制相似问题