Debconf fallback to readline instead of non-interactive

I found an interesting edge case. Running commands in a LXD container is non-interactive as one would expect (at least when you use it via pyLXD

But apparently debconf falls back to readline as frontend according to my logs:

debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline

Which can lead to a situation like this where it hangs forever

root        7632  0.0  0.3  51844 48808 ?        Ss   Dec08   0:20 apt-get install --yes --no-install-recommends <package>
root        7729  0.0  0.0   7024  3604 pts/1    Ss+  Dec08   0:00 /usr/bin/dpkg --status-fd 42 --configure --pending
root        7766  0.0  0.0  14980 12076 pts/1    S+   Dec08   0:00 /usr/bin/perl -w /usr/share/debconf/frontend /var/lib/dpkg/info/openssh-server.postinst configure 1:7.4p1-10+deb9u6
root        7779  0.0  0.0   2336   628 pts/1    S+   Dec08   0:00 /bin/sh /var/lib/dpkg/info/openssh-server.postinst configure 1:7.4p1-10+deb9u6
root        7782  0.0  0.0   5456  3464 pts/1    S+   Dec08   0:00 /bin/bash /usr/bin/ucf --three-way --debconf-ok --sum-file /usr/share/openssh/sshd_config.md5sum /tmp/filem7V2oS /etc/ssh/sshd_config

A way to workaround this problem is to set DEBIAN_FRONTEND=noninteractive manually.

Has anyone had similar problems and how did you solve them?
Is there a way to force a real non-interactive mode from LXD side or can this only be fixed inside the container.

This is a frequent problem for configuration managers and other unattended tools driving apt/dpkg and setting DEBIAN_FRONTEND to noninteractive is the usual method used by all of those.

1 Like