`docker start` 与 `docker 运行` 的选项

Options for `docker start` vs `docker run`

我在概念上遇到了一些 Docker 命令的困难时期。让我们假设,不完全是假设,我正在构建一个需要 --privileged 的图像。我想不出办法做到这一点。让我们进一步假设我将需要权限的步骤推迟到第一个 运行- 然后我忘记为第一个 运行 指定 --privileged。现在我有一个容器 - docker start 也不会让我指定 --privileged。当我忘记在 Docker 文件或 docker run 中指定 shell 时,docker start 也存在类似的问题。有没有办法解决这些问题?

示例Docker文件:

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. What you can do, however, is to make your changes on a container with docker run --privileged, then use docker commit 将其转换回图像:

$ docker run -ti <image>
# do your thing...

$ docker commit <container id> final-image:version