Post

Container-Friendly Debian Package Configuration

Container builds requires a hands off non-interactive mechanism to bring together an image for deployment. Seems most packages provide either a configuration files or environment variables that can be set before hand to allow easy setup without manual intervention during the installation process.

When building a docker image at times you will see the following error shown below. This particular error doesn’t appear to stop the docker build process from completing. Instead we know that we can switch to apt-get which removes the seemingly alarming WARNING message:

1
2
3
4
5
...
STEP 2/3: RUN apt update

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
...

Now when installing console-setup in a docker build process we are presented with the following errors:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
...
Setting up keyboard-configuration (1.240) ...
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 (you may need to install the Term::ReadLine module) (@INC entries checked: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.40.1 /usr/local/share/perl/5.40.1 /usr/lib/x86_64-linux-gnu/perl5/5.40 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl-base /usr/lib/x86_64-linux-gnu/perl/5.40 /usr/share/perl/5.40 /usr/local/lib/site_perl) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 8.)
...
Setting up console-setup (1.240) ...
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 (you may need to install the Term::ReadLine module) (@INC entries checked: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.40.1 /usr/local/share/perl/5.40.1 /usr/lib/x86_64-linux-gnu/perl5/5.40 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl-base /usr/lib/x86_64-linux-gnu/perl/5.40 /usr/share/perl/5.40 /usr/local/lib/site_perl) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 8.)

The build process is able to complete even with these errors appearing however this particular is a little more worrying. With the package console-setup and its dependencies we are required to preconfigure some options in the CLI during the installation process. This is the cause of the errors.

As we are working with Debian there is the option to add DEBIAN_FRONTEND=noninteractive to inform apt-get to avoid requiring interactions. This doesn’t work in fixing the issue as the installation requires manual intervention.

There is also the option to install in quiet mode that can be triggered with apt-get install -q or even -qq which the man page. This also doesn’t help remove the errors in the build process.

This led me down a rabbit hole of testing a manual installation of the package console-setup and figuring out how to configure the package to complete a Docker build.

The place to start is with a quick docker image as follows:

1
sudo docker run --rm -it debian:trixie-slim bash

Then go ahead and install the package:

1
2
apt-get update
apt-get install -y console-setup

Now during the installation process we are prompted to choose the following options to preconfigure the packages:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Preconfiguring packages ...
Configuring keyboard-configuration
----------------------------------

Please select the layout matching the keyboard for this machine.

  1. English (US)                                     11. English (US) - English (Dvorak, alt. intl.)             21. English (US) - English (Workman)
  2. English (US) - Cherokee                          12. English (US) - English (Dvorak, intl., with dead keys)  22. English (US) - English (Workman, intl., with dead keys)
  3. English (US) - English (Colemak)                 13. English (US) - English (Dvorak, left-handed)            23. English (US) - English (classic Dvorak)
  4. English (US) - English (Colemak-DH ISO)          14. English (US) - English (Dvorak, right-handed)           24. English (US) - English (intl., with AltGr dead keys)
  5. English (US) - English (Colemak-DH Ortholinear)  15. English (US) - English (Macintosh)                      25. English (US) - English (programmer Dvorak)
  6. English (US) - English (Colemak-DH Wide ISO)     16. English (US) - English (Norman)                         26. English (US) - English (the divide/multiply toggle the layout)
  7. English (US) - English (Colemak-DH Wide)         17. English (US) - English (US, Symbolic)                   27. English (US) - Hawaiian
  8. English (US) - English (Colemak-DH)              18. English (US) - English (US, alt. intl.)                 28. English (US) - Russian (US, phonetic)
  9. English (US) - English (Dvorak)                  19. English (US) - English (US, euro on 5)                  29. English (US) - Serbo-Croatian (US)
  10. English (US) - English (Dvorak, Macintosh)      20. English (US) - English (US, intl., with dead keys)      30. Other
Keyboard layout: 1

Configuring console-setup
-------------------------

  1. ARMSCII-8  3. CP1255  5. GEORGIAN-ACADEMY  7. IBM1133     9. ISO-8859-1    11. ISO-8859-11  13. ISO-8859-14  15. ISO-8859-16  17. ISO-8859-3  19. ISO-8859-5  21. ISO-8859-7  23. ISO-8859-9  25. KOI8-U   27. UTF-8
  2. CP1251     4. CP1256  6. GEORGIAN-PS       8. ISIRI-3342  10. ISO-8859-10  12. ISO-8859-13  14. ISO-8859-15  16. ISO-8859-2   18. ISO-8859-4  20. ISO-8859-6  22. ISO-8859-8  24. KOI8-R      26. TIS-620  28. VISCII
Encoding to use on the console: 1

Please choose the character set that should be supported by the console font.

If you don't use a framebuffer, the choices that start with "." will reduce the number of available colors on the console.

  1. . Arabic                                                        9. # Georgian                                                            17. # Latin7 - Lithuanian; Latvian; Maori and Marshallese
  2. # Armenian                                                      10. # Greek                                                              18. . Latin - Vietnamese
  3. # Cyrillic - KOI8-R and KOI8-U                                  11. . Greek (for blind users)                                            19. # Thai
  4. # Cyrillic - non-Slavic languages                               12. # Hebrew                                                             20. . Combined - Latin; Slavic Cyrillic; Hebrew; basic Arabic
  5. . Cyrillic - non-Slavic languages (for blind users)             13. # Lao                                                                21. . Combined - Latin; Slavic Cyrillic; Greek
  6. # Cyrillic - Slavic languages (also Bosnian and Serbian Latin)  14. # Latin1 and Latin5 - western Europe and Turkic languages            22. . Combined - Latin; Slavic and non-Slavic Cyrillic
  7. . Cyrillic - Slavic languages (for blind users)                 15. # Latin2 - central Europe and Romanian                               23. Guess optimal character set
  8. . Ethiopic                                                      16. # Latin3 and Latin8 - Chichewa; Esperanto; Irish; Maltese and Welsh
Character set to support: 1

There is one detail we must take particular note in the output we are presented. The following lines below actually highlight the names of the packages we are configuring:

1
2
3
4
5
6
7
Preconfiguring packages ...
Configuring keyboard-configuration
----------------------------------
...
Configuring console-setup
-------------------------
...

Once the installation is complete we can check with the following command debconf-show the options that we previously configured during the installation process:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
> debconf-show keyboard-configuration
* keyboard-configuration/variant: English (US)
  keyboard-configuration/compose: No compose key
  keyboard-configuration/unsupported_config_layout: true
  keyboard-configuration/store_defaults_in_debconf_db: true
  keyboard-configuration/unsupported_config_options: true
  keyboard-configuration/unsupported_layout: true
  debian-installer/console-setup-udeb/title:
  keyboard-configuration/modelcode: pc105
  keyboard-configuration/variantcode:
  keyboard-configuration/xkb-keymap: us
  keyboard-configuration/model: Generic 105-key PC
  keyboard-configuration/toggle: No toggling
  keyboard-configuration/switch: No temporary switch
  keyboard-configuration/optionscode:
  keyboard-configuration/other:
  keyboard-configuration/layoutcode: us
  keyboard-configuration/layout:
  keyboard-configuration/ctrl_alt_bksp: false
  keyboard-configuration/altgr: The default for the keyboard layout
  keyboard-configuration/unsupported_options: true
> debconf-show console-setup
  console-setup/use_system_font:
  console-setup/fontsize-text47: 8x16
* console-setup/charmap47: ARMSCII-8
  console-setup/fontsize-fb47: 8x16
  console-setup/guess_font:
* console-setup/codeset47: . Arabic
  console-setup/codesetcode: Arabic
  console-setup/fontface47: Fixed
  console-setup/framebuffer_only:
  console-setup/fontsize: 8x16
  console-setup/store_defaults_in_debconf_db: true

Another important detail is the * at the start of some of the configuration options. These indicate the configurations that were chosen by us manually during the installation process earlier.

Armed with this information we can use the package debconf-set-selections to preconfigure the options for unattended installation. We need to add the pacakge name to the start of each configuration option and modify the configurations with String, Boolean etc. depending on the options as follows:

1
2
3
debconf-set-selections <<< "console-setup console-setup/charmap47 string ARMSCII-8"
debconf-set-selections <<< "console-setup console-setup/codeset47 string Arabic"
debconf-set-selections <<< "keyboard-configuration keyboard-configuration/variant string English (US)"

There is also the option to add these configuration selections to a file and run the debconf-set-selections command to set the options:

1
2
3
4
echo "console-setup console-setup/charmap47 string ARMSCII-8" >> /root/selections
echo "console-setup console-setup/codeset47 string Arabic" >> /root/selections
echo "keyboard-configuration keyboard-configuration/variant string English (US)" >> /root/selections
debconf-set-selections /root/selections

To verify the options that have been set you can run the command debconf-show. The below output is from a debian instance that doesn’t yet have console-setup and keyboard-configuration packages installed therefore only highlighting the options configured by us.

1
2
3
4
> debconf-show keyboard-configuration console-setup
* keyboard-configuration/variant: English (US)
* console-setup/codeset47: Arabic
* console-setup/charmap47: ARMSCII-8

Now we can put everything into a Dockerfile and test the docker build as follows:

1
2
3
4
5
6
7
8
9
10
11
FROM debian

RUN echo "console-setup console-setup/charmap47 string ARMSCII-8" >> selections
RUN echo "console-setup console-setup/codeset47 string Arabic" >> selections
RUN echo "console-setup console-setup/codesetcode string Arabic" >> selections
RUN echo "keyboard-configuration keyboard-configuration/variant string English (US)" >> selections

RUN debconf-set-selections selections

RUN apt-get update
RUN apt-get install -y console-setup

With the help of debconf-show and debconf-set-selections we can avoid misconfiguring a package and throwing unknown errors in our docker build process.

This post is licensed under CC BY 4.0 by the author.