从概念上讲,我在使用某些Docker命令时遇到了困难。让我们假设(并非完全假设)我正在构建需要--privileged
的图像。我想不出办法。让我们进一步假设,我将需要特权的步骤推迟到第一次运行时,然后忘记为第一次运行指定--privileged
。现在我有一个容器,并且docker start
也不允许我指定--privileged
。当我忘记在Dockerfile中指定 shell 程序时,用docker start
存在类似问题,或者使用docker run
时也存在类似问题。有没有办法纠正这些问题?
Dockerfile示例:
FROM ubuntu:14.04.5
ENV TERM linux
ENV DEBIAN_FRONTEND noninteractive
ENV REDDIT_USER reddit
RUN apt-get update
RUN apt-get install -y aptitude
RUN aptitude update
RUN aptitude upgrade -o Aptitude::Delete-Unused=1 -y
RUN aptitude install -y vim-nox git screen zsh wget software-properties-common
RUN git clone https://github.com/reddit-archive/reddit
RUN adduser --disabled-password --gecos "" reddit
# can't run this in build; instead, start the image with --privileged and then run the script manually
#RUN echo "y" | ./reddit/install-reddit.sh
CMD ["/bin/bash"]
EXPOSE 80
最佳答案
在构建期间,您不能以特权运行unless you use buildx。但是,您可以做的是使用docker run --privileged
在容器上进行更改,然后使用 docker commit
将其转换回图像:
$ docker run -ti <image>
# do your thing...
$ docker commit <container id> final-image:version
关于docker - `docker start`和 `docker run`的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62381001/