303

I want to install certbot in a docker environment with an Ubuntu 16.04 image:

For example:

docker run -it ubuntu:16.04 /bin/bash

When I'm inside the container, the most straightforward way to install certbot does not work as it requires user intervention:

apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository -y -u ppa:certbot/certbot && \
apt-get install -y certbot

The problem is tzdata, which stops with this interactive dialog:

Extracting templates from packages: 100%
Preconfiguring packages ...
Configuring tzdata
------------------

Please select the geographic area in which you live. Subsequent configuration
questions will narrow this down by presenting a list of cities, representing
the time zones in which they are located.

 1. Africa      4. Australia  7. Atlantic  10. Pacific  13. Etc
 2. America     5. Arctic     8. Europe    11. SystemV
 3. Antarctica  6. Asia       9. Indian    12. US
Geographic area: 

Strangely enough, it works when I install tzdata before adding the ppa:

apt-get update && \
apt-get install -y tzdata && \
apt-get install -y software-properties-common && \
add-apt-repository -y -u ppa:certbot/certbot && \
apt-get install -y certbot

Questions:

  • Why makes it a difference whether I install tzdata before or after adding the ppa?
  • Is there a better approach for avoiding the interactive dialog when installing certbot?
muru
  • 197,895
  • 55
  • 485
  • 740

5 Answers5

363

To run dpkg (behind other tools like Apt) without interactive dialogue, you can set one environment variable as

DEBIAN_FRONTEND=noninteractive

For example, you can set it in Dockerfile using ARG:

ARG DEBIAN_FRONTEND=noninteractive
  • 15
    Note: sudo doesn't pass environment variables through in most cases, so sudo DEBIAN_FRONTEND=noninteractive sudo apt-get install -y tzdata works but DEBIAN_FRONTEND=noninteractive sudo apt-get install -y tzdata doesn't. – Brendan Long Mar 21 '18 at 00:00
  • 78
    For dockerfiles, add this: ENV DEBIAN_FRONTEND=noninteractive – jersey bean Dec 26 '18 at 02:19
  • 2
    I had a case where this did not work on Ubuntu 18.04. But below answer did fix it on Ubuntu 18.04. – tmanthey Jan 27 '19 at 19:42
  • 2
    Check https://askubuntu.com/a/1098881/112499 as that answer actually fixes the issue instead of hiding it like this one. – Shadow Oct 20 '19 at 23:10
  • 6
    @jerseybean This method is highly discouraged, as explained here: https://github.com/moby/moby/issues/4032 – Akito Mar 05 '20 at 12:25
  • 1
    I thought this was what -y was supposed to accomplish. – Wyck Apr 10 '22 at 02:21
100

On Ubuntu 18.04 I did that Dockerfile:

ENV TZ=Europe/Minsk
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt update && apt instal....
85

TL&DR: Within your DockerFile

ENV DEBIAN_FRONTEND=noninteractive 

Reason:

Certain Installers make 'installations' easier by having a nice front-end. While this is great when you have a manual install, this becomes an issue during automated installations.

You can over ride the interactive installation by placing the following in your environment string.

Cheers

FlyingV
  • 969
  • 6
  • 5
29

You can set DEBIAN_FRONTEND=noninteractive before your command to avoid ENV DEBIAN_FRONTEND=noninteractive affects commands after or child image:

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
        tzdata \
    && rm -rf /var/lib/apt/lists/*
pyfreyr
  • 391
  • 3
  • 2
21

You should just set your timezone BEFORE installing of tzdata:

# Set timezone:
RUN ln -snf /usr/share/zoneinfo/$CONTAINER_TIMEZONE /etc/localtime && echo $CONTAINER_TIMEZONE > /etc/timezone

Install dependencies:

RUN apt-get update && apt-get install -y tzdata

James Bond
  • 811
  • 7
  • 5