如何从 Dockerfile 创建交互式图像?

how to create images interactive from Dockerfile?

我想从 Dockerfile 创建一个关于 PyQt5 的图像。 以下是 Dockerfile 中的部分代码。

RUN cd PyQt-gpl-5.5.1 &&\ 
        python3  configure.py

当代码执行时,它会询问我"Do you accept the terms of the license?",但我无法输入任何字词。

而且我不想使用命令 'commit'。 那么如何从 Dockerfile 创建图像 interactive

如果 shell 管道不起作用,您可以回退到 an expect script

你可以在visity/docker-build-android which install expect in its Dockerfile

中看到一个
RUN dpkg --add-architecture i386 && apt-get update && \
    apt-get install -y --force-yes expect ...

A tools/android-accept-licenses.sh 允许 docker build tp 使用 android after first accepting the license:

expect {
  "Do you accept the license '*'*" {
        exp_send "y\r"
        exp_continue
  }
  eof
}

使用by the Dockerfile:

COPY tools /opt/tools
ENV PATH ${PATH}:/opt/tools
RUN ["/opt/tools/android-accept-licenses.sh", "android update sdk --all --no-ui --filter platform-tools,tools,build-tools-22.0.1,android-22,addon-google_apis_x86-google-22,extra-android-support,extra-android-m2repository,extra-google-m2repository,sys-img-armeabi-v7a-android-22"]

这里,android-accept-licenses.sh 是宿主 /opt/tools 的一部分,它被复制到图像,然后在 RUN 指令中使用。