繁体   English   中英

如何强制 docker 容器运行和执行需要用户交互的脚本?

[英]How to force a docker container to run and execute a script that requires user interaction?

我有一个从 Dockerfile 构建的 docker 图像。 入口点中的脚本启动 Tomcat 服务器。 当脚本启动时,它会要求确认。

如果启用了交互式 shell,则脚本将等待并且 Tomcat 服务器永远不会启动。 然后我必须从容器内部手动执行 start-pentaho.sh 脚本。

如果交互式 shell 被禁用,则 tomcat 将启动。 但随后容器将获得退出的 state。

有没有办法让我的容器在不手动执行 start-pentaho 的情况下运行?

这是一个MWE:

pentaho zip 文件下载自:

https://sourceforge.net/projects/pentaho/files/Pentaho%208.1/server/pentaho-server-ce-8.1.0.0-365.zip/download

Dockerfile:

FROM ubuntu:latest
COPY ./pentaho-server-ce-8.1.0.0-365.zip /pentaho/pentaho-server-ce-8.1.zip
RUN apt-get update && \
    apt-get install unzip && \
    apt-get install -y openjdk-8-jdk
RUN unzip /pentaho/pentaho-server-ce-8.1.zip
ENTRYPOINT ["/pentaho-server/start-pentaho.sh"]

使用以下方法构建图像:

docker build -t mtleis/pentaho:v1.0 .

docker-compose.yml

pentaho:
        image:  mtleis/pentaho:v1.0
        ports:
            - "8081:8080"
# The following two lines are needed to keep the container running. However Tomcat will never start. Disabling them, Tomcat would start but the container get an exited state. 
#        stdin_open: true
#        tty: true

运行 docker-compose:

docker-compose up -d

检查容器日志:

docker logs id

WARNING: Using java from path
DEBUG: _PENTAHO_JAVA_HOME=
DEBUG: _PENTAHO_JAVA=java
--------------------------------------------------------------------------------------------
The Pentaho BI Platform now contains a version checker that will notify you
when newer versions of the software are available. The version checker is enabled by default.
For information on what the version checker does, why it is beneficial, and how it works see:
http://wiki.pentaho.com/display/ServerDoc2x/Version+Checker
Press Enter to continue, or type cancel or Ctrl-C to prevent the server from starting.
You will only be prompted once with this question.
--------------------------------------------------------------------------------------------
[OK]:
Tomcat started.

但是,如果启用了 dokcer-compose.yml 中的 2 行:

stdin_open: true
tty: true

日志显示 Tomcat 尚未启动:

WARNING: Using java from path
DEBUG: _PENTAHO_JAVA_HOME=
DEBUG: _PENTAHO_JAVA=java
--------------------------------------------------------------------------------------------
The Pentaho BI Platform now contains a version checker that will notify you
when newer versions of the software are available. The version checker is enabled by default.
For information on what the version checker does, why it is beneficial, and how it works see:
http://wiki.pentaho.com/display/ServerDoc2x/Version+Checker
Press Enter to continue, or type cancel or Ctrl-C to prevent the server from starting.
You will only be prompted once with this question.
--------------------------------------------------------------------------------------------
[OK]:

在了解容器的行为方式之后。 答案是删除用户提示并将命令tail -f /dev/null添加到入口点 shell 文件以保持容器活动。

用户提示是保持容器运行的原因。 此提示位于userprompt.sh文件中。 删除了提示read choice 现在脚本将继续执行并最终退出。 甚至使用命令运行容器

docker run -itd imagename /bin/bash

容器将退出。 这仍然是我不明白的事情。

作为一种解决方法,我最终通过在末尾添加tail -f /dev/null来编辑 start-pentaho.sh 脚本。 现在容器正在运行。

这是用于构建 pentaho 映像的新 Dockerfile:

# Dockerfile
FROM ubuntu:latest
COPY ./pentaho-server-ce-8.1.zip /pentaho/pentaho-server-ce-8.1.zip
RUN apt-get update && \
    apt-get install unzip && \
    apt-get install -y openjdk-8-jdk
RUN unzip /pentaho/pentaho-server-ce-8.1.zip -d /pentaho
# copy a modified copy of userprompt.sh file
COPY ./promptuser.sh /pentaho/pentaho-server/promptuser.sh
# copy a modified copy of the entrypoint script
COPY ./start-pentaho.sh /pentaho/pentaho-server/start-pentaho.sh
RUN chmod +x /pentaho/pentaho-server/start-pentaho.sh
ENTRYPOINT /pentaho/pentaho-server/start-pentaho.sh

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM