【问题标题】:Alpine linux in docker container ignoring shell script argumentsdocker容器中的Alpine linux忽略shell脚本参数
【发布时间】:2016-12-19 22:42:35
【问题描述】:

我正在尝试创建一个设置自定义 tomcat 端口的 docker 映像(我知道您可以使用 docker 标志“-p 8888:8080”设置外部端口,但对于我的用例,我想更改内部端口以及)。

当我尝试启动 catalina.sh 时,由于某种原因,run 参数被忽略了。

Dockerfile:

# Tomcat 8 alpine dockerfile copied here (URL below)... minus the CMD line at the end
# https://github.com/docker-library/tomcat/blob/5f1abae99c0b1ebbd4f020bc4b5696619d948cfd/8.0/jre8-alpine/Dockerfile

ADD server.xml $CATALINA_HOME/conf/server.xml
ADD start-tomcat.sh /start-tomcat.sh
RUN chmod +x /start-tomcat.sh
ENTRYPOINT ["/bin/sh","/start-tomcat.sh"]

tomcat 文件 server.xml 与默认相同,除了以下行:

<Connector port="${port.http.nonssl}" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

start-tomcat.sh:

#!/bin/sh
export JAVA_OPTS=-Dport.http.nonssl=${PORT}
catalina.sh run

图像构建成功,但是当我运行时

docker run -p 8888:8888 -e PORT=8888 customtomcat

我只是得到一个 catalina.sh 命令列表,就好像我没有给它一个参数一样。我也试过了

/usr/local/tomcat/bin/catalina.sh run

sh -c "catalina.sh run"

sh -c "/usr/local/tomcat/bin/catalina.sh run"

cd /usr/local/tomcat/bin
./catalina.sh run

我很确定我在这里遗漏了一些简单的东西。我猜它与语法有关,但可能与我不知道的 docker 或 alpine 有关。这是我第一次使用 alpine linux。

---编辑 1---

为了解释我的用例...我在创建 docker 映像后设置 PORT,因为它是由 apache mesos 任务设置的。出于我的目的,我需要在主机模式下运行 docker 容器(来自马拉松),而不是桥接模式。

---编辑 2---

我修改了一些东西,只关注我的主要问题。 docker 文件现在只在末尾附加了以下内容:

ADD start-tomcat.sh /start-tomcat.sh
RUN chmod +x /start-tomcat.sh
ENTRYPOINT ["/bin/sh","/start-tomcat.sh"]

还有 start-tomcat.sh:

#!/bin/bash
catalina.sh run

还是没有运气。

【问题讨论】:

    标签: shell docker sh alpine


    【解决方案1】:

    更新:如果“catalina.sh run”因无效选项而失败,请首先检查 Windows 系统中的换行符。在 Linux 环境中读取 shell 脚本时会导致错误。


    看看catalina.sh,我相信你想要的是CATALINA_OPTS,而不是JAVA_OPTS:

    # Control Script for the CATALINA Server
    #
    # Environment Variable Prerequisites
    #
    #   Do not set the variables in this script. Instead put them into a script
    #   setenv.sh in CATALINA_BASE/bin to keep your customizations separate.
    #
    #   CATALINA_HOME   May point at your Catalina "build" directory.
    #
    #   CATALINA_BASE   (Optional) Base directory for resolving dynamic portions
    #                   of a Catalina installation.  If not present, resolves to
    #                   the same directory that CATALINA_HOME points to.
    #
    #   CATALINA_OUT    (Optional) Full path to a file where stdout and stderr
    #                   will be redirected.
    #                   Default is $CATALINA_BASE/logs/catalina.out
    #
    #   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
    #                   "run" or "debug" command is executed.
    #                   Include here and not in JAVA_OPTS all options, that should
    #                   only be used by Tomcat itself, not by the stop process,
    #                   the version command etc.
    #                   Examples are heap size, GC logging, JMX ports etc.
    #
    #   CATALINA_TMPDIR (Optional) Directory path location of temporary directory
    #                   the JVM should use (java.io.tmpdir).  Defaults to
    #                   $CATALINA_BASE/temp.
    #
    #   JAVA_HOME       Must point at your Java Development Kit installation.
    #                   Required to run the with the "debug" argument.
    #
    #   JRE_HOME        Must point at your Java Runtime installation.
    #                   Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
    #                   are both set, JRE_HOME is used.
    #
    #   JAVA_OPTS       (Optional) Java runtime options used when any command
    #                   is executed.
    #                   Include here and not in CATALINA_OPTS all options, that
    #                   should be used by Tomcat and also by the stop process,
    #                   the version command etc.
    #                   Most options should go into CATALINA_OPTS.
    

    【讨论】:

    • 我可以看到这将如何解决问题,但即使我根本不费心设置 OPTS,问题仍然存在(请参阅编辑 2)。
    • 你是在 Windows 机器上修改 start-tomcat.sh 吗?首先猜测是文件中的 Windows 换行符。除此之外,查看您在 Dockerfile 中使用的 FROM 行将有助于缩小您正在使用的 catalina.sh 版本,或者如果您进行了更改,请包含此文件。
    • 文件的原始版本是在 windows 中创建的。我完全忘记了它,因为我一直在用 nano 编辑文件。那解决了它。我可以将此标记为正确答案,除非您想再做一个答案。
    • 我会编辑上面的评论,这样你就可以接受了。
    猜你喜欢
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 2017-12-01
    • 2022-10-20
    • 2018-04-09
    • 1970-01-01
    • 2017-07-05
    相关资源
    最近更新 更多