Docker – When building from Dockerfile, Debian/Ubuntu package install debconf Noninteractive install not allowed

docker

I've set the following environment so that no question/dialog is asked during apt-get install:

ENV DEBIAN_FRONTEND noninteractive    # export DEBIAN_FRONTEND="noninteractive"

Which is equivalent to:

export DEBIAN_FRONTEND="noninteractive"

Yet, when building an image from a Dockerfile, at the end of one specific Debian/Ubuntu package install (using apt-get install), package configuration debconf says:

debconf: unable to initialize frontend: Noninteractive    # export DEBIAN_FRONTEND="noninteractive"
debconf: (Bareword "Debconf::FrontEnd::Noninteractive" not allowed while "strict subs" in use at (eval 35) line 3, <> line 1.)
debconf: falling back to frontend: Noninteractive
Subroutine BEGIN redefined at (eval 36) line 2, <> line 1.

Best Answer

It should be actively discouraged to set the DEBIAN_FRONTEND to noninteractive via ENV. The reason is that the environment variable persists after the build, e.g. when you run docker exec -it ... bash. The setting would not make sense here.

There are two other possible ways:

  1. Set it via ARG as this only is available during build:

    ARG DEBIAN_FRONTEND=noninteractive
    RUN apt-get -qq install {your-package}
    
  2. Set it on-the-fly when required.

    RUN apt-get update && \
        DEBIAN_FRONTEND=noninteractive apt-get -qq install {your-package}