'Dockerfile to answer Y & N for single command

My dockerfile has below,

FROM ubuntu:20.04

RUN apt install -y aptitude
RUN aptitude -f install python-dev

Manual aptitude -f install python-dev installation inside the container prompts option to choose n and Y, Same as follows.

The following NEW packages will be installed:
  libpython-dev{a} libpython-stdlib{a} python{a} python-dev python-minimal{a}
0 packages upgraded, 5 newly installed, 0 to remove and 5 not upgraded.
Need to get 182 kB of archives. After unpacking 898 kB will be used.
The following packages have unmet dependencies:
 libpython2-stdlib : Breaks: libpython-stdlib (< 2.7.15-2) but 2.7.11-1 is to be installed
 python2 : Breaks: python (< 2.7.15-2) but 2.7.11-1 is to be installed
 python2-minimal : Breaks: python-minimal (< 2.7.15-2) but 2.7.11-1 is to be installed
 python-is-python2 : Breaks: python but 2.7.11-1 is to be installed
The following actions will resolve these dependencies:

     Keep the following packages at their current version:
1)     libpython-stdlib [Not Installed]
2)     python [Not Installed]
3)     python-dev [Not Installed]
4)     python-minimal [Not Installed]

Accept this solution? [Y/n/q/?] n
The following actions will resolve these dependencies:

      Remove the following packages:
1)      libpython2-stdlib [2.7.17-2ubuntu4 (focal, now)]
2)      mic [0.28.6 (now)]
3)      python-is-python2 [2.7.17-4 (focal, now)]
4)      python-pycurl [7.43.0.2-1ubuntu5 (focal, now)]
5)      python-pyparsing [2.4.6-1 (focal, now)]
6)      python-rpm [4.14.2.1+dfsg1-1build2 (focal, now)]
7)      python-urlgrabber [3.9.1-4ubuntu3 (now)]
8)      python2 [2.7.17-2ubuntu4 (focal, now)]
9)      python2-minimal [2.7.17-2ubuntu4 (focal, now)]

      Leave the following dependencies unresolved:
10)     python2-minimal recommends python2


Accept this solution? [Y/n/q/?] y

My goal is to build the docker image through dockerfile. So in Dockerfile how to respond the n and y prompts automatically for the above case? Any help would be highly appreciated.



Solution 1:[1]

You can disable interactive prompting from apt by setting the DEBIAN_FRONTEND environment variable to noninteractive. This is documented in the debconf(7) man page. That would look something like:

FROM ubuntu:20.04

RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y python-dev

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 larsks