首页 > 解决方案 > Docker:安装期间的回声输入

问题描述

我是 docker 新手,需要安装一个在安装过程中需要大量输入的文件。

在一个普通的 bash 脚本中,我会回显命令来填写输入。如何在 dockerfile 中模仿这种行为?

这是我的脚本:

#: Copy CPLEX installer binary from S3.
COPY cplex_odee1210.linux-x86-64.bin /setup/



#: Install CPLEX and update .bashrc
RUN chmod +x /setup/cplex_odee1210.linux-x86-64.bin 
RUN bash cplex_odee1210.linux-x86-64.bin 
RUN echo 2              #: - Press 2 for english 
RUN echo -ne '\n'       #: - Press ENTER to confirm prompt 
RUN echo -ne '\n'       #: - Press ENTER to continue 
RUN echo 1              #: - Press 1 to accept license agreement 
RUN echo -ne '\n'       #: - Press ENTER to confirm prompt 
RUN echo -ne '\n'       #: - Press ENTER to accept default path 
RUN echo -ne '\n'       #: - Press ENTER to install 
RUN echo -ne '\n'       #: - Press ENTER to continue 
RUN echo -ne '\n'       #: - Press ENTER to continue 
RUN echo 2              #: - Press 2/ENTER to say no to product usage data collection 
RUN echo -ne '\n'       #: - Press ENTER to confirm prompt 
RUN echo -ne '\n'       #: - Press ENTER to exit the installer 
RUN echo 'export PATH=$PATH:/opt/ibm/ILOG/CPLEX_Optimizer1210/cplex/bin/x86-64_linux' >>~/.bashrc 
RUN source ~/.bashrc

这是运行的,但没有通过这一步:

Step 9/54 : RUN bash cplex_odee1210.linux-x86-64.bin
 ---> Running in c6404632b1b0
Preparing to install
Extracting the JRE from the installer archive...
Unpacking the JRE...
Extracting the installation resources from the installer archive...
Configuring the installer for this system's environment...

Launching installer...

===============================================================================
Choose Locale...
----------------

    1- Deutsch
  ->2- English
    3- Espa?ol
    4- Fran?ais
    5- Portugu?s  (Brasil)

CHOOSE LOCALE BY NUMBER: 

我需要将我的 bash 运行命令链接在一起吗?有没有办法做到这一点?

标签: dockerdocker-composedockerfile

解决方案


在 Dockerfile 中,每个 RUN 语句都是按顺序执行的。如前所述,您不能运行交互式程序,并且需要以其他方式传递输入(如果您不能重构程序,您可以使用 shell 重定向来提供来自文件的输入或使用 heredoc) .


推荐阅读