2

カスタム 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" />

開始-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と関係があるかもしれません。アルパイン Linux を使用するのはこれが初めてです。

---編集1---

私のユースケースを説明するには... Dockerイメージが作成された後にポートを設定しています。これは、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

まだ運がありません。

4

1 に答える 1

2

更新: "catalina.sh run" が無効なオプションで失敗する場合は、まず Windows システムからの改行を確認してください。Linux 環境でシェル スクリプトを読み込むと、エラーが発生します。


catalina.sh を見ると、JAVA_OPTS ではなく CATALINA_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.
于 2016-08-12T21:43:33.383 に答える