docker容器中的高山linux忽略shell脚本参数
我试图创build一个设置自定义tomcat端口的docker镜像(我知道你可以用docker标志设置一个外部端口“-p 8888:8080”,但是对于我的用例,我想改变内部端口) 。
当我尝试启动catalina.sh运行参数由于某种原因被忽略。
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
图像build立成功,但是当我运行
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有关,我不知道。 这是我第一次使用高山linux。
—编辑1 —
为了解释我的用例…我在创builddocker镜像之后设置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
仍然没有运气。
更新:对于“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.