我正在尝试创建一个设置自定义 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" />
启动 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
仍然没有运气。