如何使用 ubuntu 18.04(仿生)构建 docker python 容器?

How to build the docker python container with ubuntu 18.04 (bionic)?

Python 提供 docker 个图像 (https://hub.docker.com//python/), which come in a variety of flavours (based on different images from: https://hub.docker.com//buildpack-deps/)。不幸的是,none 以 ubuntu 18.04(仿生)作为基础提供。我想建造那个。

我最初认为我应该从 "real" ubuntu 18.04 docker 映像 (https://hub.docker.com/r/library/ubuntu/) 开始并安装相关的 ubuntu 软件包,但是生成的 docker 图像似乎很快就变大了,当然不会引入当前的 python 版本 (3.7.0)。

接下来,我尝试简单地构建 docker 集线器 (https://github.com/docker-library/python/blob/8601079d1f70b03c01408377716a3243ce75cec9/3.7/stretch/Dockerfile) 上提供的确切 Docker 文件,但将 FROM buildpack-deps:stretch 替换为 FROM buildpack-deps:bionic .不幸的是,该构建似乎需要对我的区域进行某种交互式选择,我不知道如何解决这个问题(下面的输出)。

关于如何预配置此构建使其不询问我区域/如何禁用该提示的任何建议?

我看到了使用 expect 的建议,但不知道是否可以轻松地将其集成到 docker 构建中。

Docker 构建输出

[...]
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:用原始 FROM buildpack-deps:stretch 构建 docker 图像似乎工作正常,因此此交互式选择与仿生基础有关。

简而言之:不要这样做。

我不知道 Ubuntu (18.04) bionic 不再基于 Debian stretch,但现在实际上是基于 Debian buster。因此,与其尝试在 ubuntu 之上构建它,我还可以在 buster 之上构建它并简单地使用:

FROM buildpack-deps:buster

这是我从 Ubuntu Stretch 开始必须做的事情,我更改了:

FROM ubuntu

为了通过 tzdata 提示,在 apt-get 行之前插入环境变量(编辑使用 ARG 而不是 ENV,这样它只适用于 docker 构建而不适用于容器是运行):

ARG DEBIAN_FRONTEND=noninteractive

然后你需要apt-get所有这些包:

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

我还需要在所有 wget 调用中添加 --no-check-certificate 选项。