首页 > 解决方案 > 尝试创建自定义 Docker 映像,但在 RUN 步骤中被询问问题

问题描述

我正在尝试创建一个自定义 Docker 映像,并且在其中一个RUN步骤中,我被要求选择一些“菜单”选项..它会挂起/停止图像继续/制作。

这是 Dockerfile:

FROM ubuntu:latest

RUN apt update

# install OpenCV
RUN apt install python3-opencv -y

# Test that OpenCV has been installed
RUN python3 -c "import cv2; print(cv2.__version__)"

这是构建输出中的最后几行:

....
Setting up libsnappy1v5:amd64 (1.1.8-1build1) ...
Setting up poppler-data (0.4.9-2) ...
Setting up libkrb5support0:amd64 (1.17-6ubuntu4) ...
Setting up libsasl2-modules-db:amd64 (2.1.27+dfsg-2) ...
Setting up tzdata (2020a-0ubuntu0.20.04) ...
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: 

这是第三步的一部分 =>RUN p3 p3-opencv

我怎样才能让这一步自动完成?我猜想在尝试安装python-opencv时我缺少依赖项和/或需要更新一些依赖项。这很好,它正在尝试更新/安装这些,但需要一些用户交互。

标签: pythondockeropencv

解决方案


您可以使用DEBIAN_FRONTEND=noninteractive

FROM ubuntu:latest
RUN apt update
ENV DEBIAN_FRONTEND=noninteractive

# install OpenCV
RUN apt install python3-opencv -y

# Test that OpenCV has been installed
RUN python3 -c "import cv2; print(cv2.__version__)"

推荐阅读