9

When I build a Ubuntu 18.04 image with docker it prompts for

Country of origin for keyboard:

and after I enter a number it hangs. Here is my Dockerfile:

FROM ubuntu:18.04

RUN apt update
RUN apt install software-properties-common -y
RUN add-apt-repository ppa:graphics-drivers 
RUN apt install nvidia-driver-440 -y

What do I have to do to build a ubuntu 18.04 image with Docker?

Dean Schulze
  • 9,633
  • 24
  • 100
  • 165

2 Answers2

11

You can skip that interactive input if you set this environment variable: DEBIAN_FRONTEND=noninteractive.

The Dockerfile should look like this:

FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update
RUN apt install software-properties-common -y
RUN add-apt-repository ppa:graphics-drivers
RUN apt install nvidia-driver-440 -y
Neo Anderson
  • 5,957
  • 2
  • 12
  • 29
  • 1
    The key is that DEBIAN_FRONTEND has to be set in the Dockerfile, not in the host you are building from. – Dean Schulze Aug 18 '20 at 21:16
  • 3
    It's also important for layer-caching purposes to do `apt-get update && apt-get install` in the same `RUN` instruction, and I generally set `DEBIAN_FRONTEND` only in that single `RUN` line to avoid it leaking out to the rest of the image. – David Maze Aug 18 '20 at 21:58
  • @DavidMaze, how do you set it in the same line? – Danijel May 10 '23 at 07:56
  • Simply chain the commands with `&&`, exactly as David suggested in the previous comment. E.g: `RUN apt-get update && apt-get install`. This will only add one layer in the UFS instead of two. You may find [this](https://stackoverflow.com/questions/39223249/multiple-run-vs-single-chained-run-in-dockerfile-which-is-better) post useful in respect to optimisation of the layers created during a docker build. – Neo Anderson May 10 '23 at 09:27
4
  • Most issues will be solved by adding ENV DEBIAN_FRONTEND=noninteractive in your Dockerfile.

  • Sometimes though, I still get this warning even with this line. This extra line fixes this:


ENV DEBIAN_FRONTEND=noninteractive
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
Ben Butterworth
  • 22,056
  • 10
  • 114
  • 167