105

Is it possible to somehow answer the questions that are presented as dialogs when installing some packages using apt-get?

For instance I'm trying to setup a container containing the mail-stack-delivery package with:

FROM ubuntu

RUN apt-get install -y mail-stack-delivery

However that dockerfile generates dozens of errors when built that are along the lines of:

debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7, <> line 11.)
debconf: falling back to frontend: Teletype
dpkg-preconfigure: unable to re-open stdin: 

From what I understand I just simply can't respond to the dialogs, but is there some way that I can pass a parameter to answer each question in advance? I know that it's just changing some configurations, so I could do it after the fact, but presumably it's better to let the install scripts do it so everything gets set properly.

8 Answers 8

119

See the discussion here: https://github.com/docker/docker/issues/4032. In short, setting ENV DEBIAN_FRONTEND noninteractive is not recommended as it persists in the final image, even when running something like docker run -i -t ... bash. Therefore it is recommended either to omit DEBIAN_FRONTEND and live with the warning, or specify it explicitly for each command e.g. RUN DEBIAN_FRONTEND=noninteractive apt-get install -y -q package.

Fortunately, the new ARG directive sets variables that only live during the build so a more elegant solution is now possible that's specified in the DockerFile yet does not persist in the final image: ARG DEBIAN_FRONTEND=noninteractive.

1
  • I had a RUN apt-get -y -qq install python-pip php-mbstring php-bcmath that was stopping the building of my dockerfile at a prompt with message A new version (/usr/lib/php/7.0/php.ini-production.cli) of configuration file /etc/php/7.0/cli/php.ini is available, but the version installed currently has been locally modified .... What do you want to do about modified configuration file php.ini ... 1. install the new version, 2. keep the local version .... Adding this env var ommitted the prompt
    – Shadi
    Aug 26, 2016 at 8:53
26

You should set DEBIAN_FRONTEND=noninteractive as an envvar. In most cases this will at least make it so the installation doesn't error out.

Also as @Azdle mentioned, using debconf-set-selections will let you set specific items.

19

As usual, a little more searching found the answer.

The answer is debconf-set-selections. Manpage: http://manpages.ubuntu.com/manpages/oneiric/en/man1/debconf-set-selections.1.html

To find the options that can be set use debconf-get-selections on a system that already has the package installed. You'll need to install debconf-utils for the second command.

13

ENV DEBIAN_FRONTEND noninteractive didn't work for me

neither did ARG DEBIAN_FRONTEND=noninteractive

but RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections did

0
10

This is working solution:

ARG DEBIAN_FRONTEND=noninteractive

4
  • 5
    Could you please explain your answer? Like why it works, what was the problem etc. Jun 18, 2017 at 19:57
  • 1
    Sure. I had the same problem. I tried to add "RUN DEBIAN_FRONTEND=noninteractive apt-get install", but received the same error. If I add "RUN DEBIAN_FRONTEND=noninteractive" to all apt-get commands, then it works fine. After that I added "ARG DEBIAN_FRONTEND=noninteractive" and it works like a charm! Sorry for my answer, I am newbie here. I can delete it :)
    – vovando
    Jun 18, 2017 at 20:22
  • 1
    A good answer does not just fix the problem but also explain the reasoning behind it. For example look at the accepted answer. So I suggest you either edit your answer heavily and include some background information about why those commands work or you delete it. I know you meant good - but ultimately we want to keep a high standard. Jun 18, 2017 at 20:36
  • 1
    Downvote. This solution has already been mentioned in the last part of the accepted answer a year before. Feb 15, 2021 at 22:02
8

EXAMPLE With Success:

echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
sudo apt-get install -y -q <package name>
2

Adding the tiny package 'dialog' also resolves this issue.

&& sudo apt-get -y install dialog
1

The reason why ENV DEBIAN_FRONTEND=noninteractive (or the legacy syntax ENV DEBIAN_FRONTEND noninteractive) sometimes works and sometimes does not has to do with the usage of sudo. By default sudo ignores the environment of the current user and uses a clean one. This can be controlled via the sudo --preserve-env flag. Obviously adding this to every sudo invocation is cumbersome, but it is easy to make the entire system for every user non-interactive by adding the environment variable to the /etc/environment file of the operating system.

RUN set -a \
 && eval "$(sudo tee --append /etc/environment <<<'DEBIAN_FRONTEND=noninteractive')" \
 && set +a \
 && sudo apt-get update \
 && sudo apt-get install mail-stack-delivery

Quickly dissecting the important snippet in isolation:

# export every variable that follows
set -a

# appends the given string to the `/etc/environment` file as root
# tee prints its input to standard out
# eval interprets the output of tee
eval "$(sudo tee --append /etc/environment <<<'DEBIAN_FRONTEND=noninteractive')"

# stop exporting everything
set +a

It was mentioned before the DEBIAN_FRONTEND=noninteractive should not be set in such a global fashion. This depends on what the intend of your image is. If it is meant for automation and not for humans then it is totally fine to set it globally.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.