Docker: Having issues installing apt-utils

前端 未结 2 448
旧巷少年郎
旧巷少年郎 2021-01-30 01:03

I am trying to install apt-utils on Docker because when I was just doing apt-get update, I was getting the error: debconf: delaying package confi

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 01:45

    After searching over the Internet, I have found some alternatives worth to be mentioned, instead of every time putting DEBIAN_FRONTEND=noninteractive in front of apt-get install -y {your-pkgs}:

    Alternative 1: ARG DEBIAN_FRONTEND=noninteractive

    The ARG instruction defines a variable that users can pass at build-time to the builder with the docker build command using the --build-arg = flag. (Reference: [6])

    Solution characteristics:

    • ARG directive is set only during the build
    • The option 'noninteractive' is set as default value for the build-time only.
    • Since it is an argument, it can be changed by passing another value for this argument with e.g. docker build --build-arg DEBIAN_FRONTEND=newt

    Example:

    ARG DEBIAN_FRONTEND=noninteractive
    ...
    RUN apt-get -yq install {your-pkgs}
    

    Alternative 2: On-the-fly

    It is the solution from Leo K.

    Solution characteristics:

    • It can be set where is it needed. So a good fine-grained solution.
    • It can be set in a different value in a specific command, so it is not globally set.
    • The scope is the RUN and won't affect other directives.

    Example:

    RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install {your-pkgs}
    

    Alternative 3: ENV DEBIAN_FRONTEND=noninteractive

    Setting ENV DEBIAN_FRONTEND noninteractive would also be an alternative but it is highly discouraged.

    Another way would be to set at the begging and unset it at the end of the Dockerfile.

    Solution characteristics:

    • ENV directive will persists the environment variable after the build (not recommended), furthermore
    • It can be error prone if you forget to set it back to the default value.
    • Because it is set with ENV, it will be inherited by all images and containes built from the image, effectively changing their behaviour. (As mentioned in [1]) People using those images run into problems when installing software interactively, because installers do not show any dialog boxes.
    • The default frontend is DEBIAN_FRONTEND=newt (see [2], so it has to be set at the end of the file.

    Example:

    # Set for all apt-get install, must be at the very beginning of the Dockerfile.
    ENV DEBIAN_FRONTEND noninteractive
    ...
    # Non-interactive modes get set back.
    ENV DEBIAN_FRONTEND newt
    

    Alternative 4: RUN export DEBIAN_FRONTEND=noninteractive

    Solution characteristics:

    • Quite similar to the alternative 2
    • By decoupling, the cohesion is suffering: why there is an export of this variable and to what it belongs to (apt-get).
    • The scope is the RUN and won't affect other directives.

    Example:

    # Set the frontend and then install your package
    RUN export DEBIAN_FRONTEND=noninteractive && \
        ...
        apt-get -yq install {your-pkgs} && \
        ...
    

    More to read (references)

    • ENV DEBIAN_FRONTEND noninteractive
    • debconf: delaying package configuration, since apt-utils is not installed
    • point out that ENV DEBIAN_FRONTEND will persist, so its not recommended
    • Docker frequently asked questions (FAQ)
    • Debian Installer Parameters
    • Official documentation - ARG

提交回复
热议问题