2

I'm buildinga a docker image using a Dockerfile to build it. I have put ARG DEBIAN_FRONTEND=noninteractive in the beginning of the Dockerfile to avoid debconf warnings while building.

The warnings does not show up when using apt-get install inside the Dockerfile. However when executing a sh script (install_dependencies.sh) from the Dockerfile that contains apt-get install commands, the warnings show up again. I also tried to set DEBIAN_FRONTEND=noninteractive inside the sh script itself.

I can solve this by adding echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections in the sh script before the apt-get install commands but I would want to avoid that, since any fail in the script would leave debconf select to Noninteractive.

Dockerfile:

FROM ubuntu:18.04

# Avoid warnings by switching to noninteractive
ARG DEBIAN_FRONTEND=noninteractive

WORKDIR /tmp

# Configure APT --> HERE THE WARNINGS 'debconf: unable to initialize frontend: Dialog' ARE NOT DISPLAYED
RUN apt-get update \
    && apt-get -y upgrade \
    && apt-get install -y \
    apt-utils \
    dialog \
    fakeroot \
    software-properties-common \
    2>&1

# Install APT packages --> HERE THE WARNINGS 'debconf: unable to initialize frontend: Dialog' ARE NOT DISPLAYED
RUN apt-get update && apt-get install -y \
    #
    # System packages
    iproute2 \
    procps \
    lsb-release \
    sudo \
    unattended-upgrades \
    dnsutils \
    iputils-ping \
    xauth \
    openssl \
    tar \
    zip \
    #
    # Helpers
    && apt-get install -y \
    ca-certificates \
    curl \
    wget \
    lsof \
    gconf2 \
    gconf-service \
    #
    # Clean up
    && apt-get autoremove -y \
    && apt-get clean -y \
    && rm -rf /var/lib/apt/lists/*

# Install LTE stack dependencies --> HERE THE WARNINGS 'debconf: unable to initialize frontend: Dialog' ARE DISPLAYED
RUN chmod +x install_dependencies.sh \
    && export DEBIAN_FRONTEND=noninteractive; ./install_dependencies.sh

install_dependencies.sh:

#!/bin/sh

export DEBIAN_FRONTEND=noninteractive

APT_PACKAGES="lib32z1 \
    python-setuptools \
    libmysqlclient-dev \
    ninja-build"

install_apt_packages() {
    sudo apt-get install -y tzdata \
        build-essential \
        git

    for package in $APT_PACKAGES;
    do
        sudo apt-get -y install "$package";
    done
}

main() {
    sudo apt-get update && sudo apt-get upgrade -y 
    install_apt_packages
}

main

EDIT: Thanks to @arkadiusz-drabczyk for telling me to remove sudo from the apt-get commands, it makes perfect sense what he says, that the environment variables drop before executing the command.

Eduardo G
  • 370
  • 4
  • 17

1 Answers1

5

Drop sudo in your script, there is point to use it if you're running as root. This is also the reason that DEBIAN_FRONTEND has no effect - sudo drops your current user's environment for security reasons, you'd have to use with -E option to make it work.

Arkadiusz Drabczyk
  • 11,227
  • 2
  • 25
  • 38
  • I tried to remove sudo and it still does not work I guess – Eduardo G Dec 05 '21 at 17:29
  • you *guess*? What happens when you just run Ubuntu Docker container with `docker run --rm -it ubuntu:18.04` and then do `apt-get update`, `export DEBIAN_FRONTEND=noninteractive` and `apt-get install -y tzdata`? – Arkadiusz Drabczyk Dec 05 '21 at 17:33
  • I tried to use apt-get instead sudo apt-get and it does not work ... – Eduardo G Dec 05 '21 at 17:44
  • 1
    _it does not work_ is not a good explanation. You have to be more specific if you want someone to help you. – Arkadiusz Drabczyk Dec 05 '21 at 17:45
  • [@arkadiusz-drabczyk](https://stackoverflow.com/users/3691891/arkadiusz-drabczyk) Look at EDIT in the question please. – Eduardo G Dec 05 '21 at 17:59
  • Wait, you don't even add the script to your docker image. Add `ADD install_dependencies.sh /tmp` in Dockerfile before building the image. – Arkadiusz Drabczyk Dec 05 '21 at 18:08
  • [@arkadiusz-drabczyk](https://stackoverflow.com/users/3691891/arkadiusz-drabczyk) Oh, yes sorry you were right, just removing sudo before apt-commands resolves my issue. I was just using an wrong (old) install_dependencies.sh script ... my bad. – Eduardo G Dec 05 '21 at 18:14