4

Python provides docker images (https://hub.docker.com//python/), which come in a variety of flavours (based on different images from: https://hub.docker.com//buildpack-deps/). Unfortunately, none are provided with ubuntu 18.04 (bionic) as a base. I would like to build that.

I initially thought I should just start off with a "real" ubuntu 18.04 docker image (https://hub.docker.com/r/library/ubuntu/) and install relevant the ubuntu packages, but the resulting docker image appears to get pretty large quickly and of course doesn't pull in the current python release (3.7.0).

Next, I tried to simply build the exact Dockerfile provided on docker hub (https://github.com/docker-library/python/blob/8601079d1f70b03c01408377716a3243ce75cec9/3.7/stretch/Dockerfile), but replace the FROM buildpack-deps:stretch with FROM buildpack-deps:bionic. Unfortunately, the build appears to require some sort of interactive selection of my region and I don't see how I can get around that (output below).

Any suggestions on how to pre-configure this build so it doesn't ask me for the region / how to disable that prompt?

I saw suggestions using expect, but no idea if that can easily be integrated into the docker build.

Docker build output

[...]
Setting up tzdata (2018d-1) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
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:

PS: Building the docker image with the original FROM buildpack-deps:stretch appears to work fine, so this interactive selection is something related to the bionic base.

Chris
  • 3,245
  • 4
  • 29
  • 53
  • Why do you need Ubuntu (this may help provide an alternative answer, or help us to see that this is the best way to do it). – ctrl-alt-delor Sep 10 '18 at 13:51
  • plenty of reasons - mostly for consistency of the build - do you think it would be easier to build in Debian? – Chris Sep 10 '18 at 13:52
  • What benefit does changing the Ubuntu version give? – OneCricketeer Sep 10 '18 at 13:52
  • mostly it brings additional packages, which I need for other packages that are supposed to run in the final container – Chris Sep 10 '18 at 13:53
  • Such as what? Ubuntu is Debian based, so whatever packages you need, put them in your own layer. I'm not sure I understand the purpose here unless you are trying to ensure that you always have a base Ubuntu bionic image for caching purposes – OneCricketeer Sep 10 '18 at 13:56
  • so are you saying I should just use `buster` then instead of the `bionic` ? – Chris Sep 10 '18 at 14:02

2 Answers2

2

Here is what I had to do starting from Ubuntu Stretch, I changed:

FROM ubuntu

In order to get pass the tzdata prompt, insert the environment variable before the apt-get line (edit use ARG instead of ENV so that it only applies to the docker build and not when the container is running):

ARG DEBIAN_FRONTEND=noninteractive

Then you need to apt-get all these packages:

RUN apt-get update && apt-get install -y --no-install-recommends \
wget gpg dirmngr gpg-agent build-essential checkinstall tk-dev \
libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev \
libgdbm-dev libc6-dev libbz2-dev

I also needed to add the --no-check-certificate option in all the wget calls.

kamion
  • 461
  • 2
  • 9
  • The question was complaining about image size; if that’s at all a concern then you shouldn’t install `build-essential` in your base (runtime) image, it brings along a ton of stuff you don’t need to just run services. – David Maze Oct 29 '18 at 17:49
  • I'm open to anyone who can give us a slimmed down version of the apt-get packages that would work with getting python on Ubuntu Bionic. – kamion Oct 29 '18 at 17:56
  • thanks for the reference to `ENV DEBIAN_FRONTEND noninteractive` I had recently started seeing this in other Dockerfiles and was wondering why it was required. One way to keep the Docker image small might be to have a single `RUN` command (as you do) that **also uninstalls** `build-essential` again if it is only needed during the docker build, but you have to make sure it's all in the same `RUN` command otherwise Docker creates layers including that package... I'm not sure when `build-essential` related packages are required here, though. – Chris Nov 01 '18 at 04:37
1

In short: don't do it.

I wasn't aware that Ubuntu (18.04) bionic was no longer based on Debian stretch, but is now actually based on Debian buster. So instead of trying to build this on top of ubuntu, I can also just build it on top of buster and simply use:

FROM buildpack-deps:buster

Chris
  • 3,245
  • 4
  • 29
  • 53