2016-08-12 6 views
1

Ich versuche, ein Docker-Bild erstellen, die einen benutzerdefinierten Tomcat-Port setzt (Ich weiß, dass Sie einen externen Port mit dem Andock-Flag "-p 8888: 8080" aber für meine festlegen können Anwendungsfall Ich möchte auch den internen Port ändern).Alpine Linux in Docker Container ignorieren Shell-Skript Argumente

Wenn ich versuche, catalina.sh zu starten, wird das Argument run aus irgendeinem Grund ignoriert.

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"] 

Die Kater-Datei server.xml, ist das gleiche wie der Standard mit Ausnahme der Zeile:

<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 

Das Image wird erfolgreich erstellt, aber wenn ich mit

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

Ich bekomme nur eine Liste von catalina.sh-Befehlen, als ob ich ihm kein Argument gegeben hätte. Ich habe auch versucht

/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 

Ich bin mir ziemlich sicher, dass ich etwas Einfaches hier vermisse. Ich nehme an, es hat etwas mit der Syntax zu tun, aber vielleicht hat es etwas mit docker oder alpin zu tun, das mir nicht bewusst ist. Dies ist mein erstes Mal mit alpinem Linux.

--- Edit 1 ---

Zu meinem Anwendungsfall zu erklären ... Ich gründe PORT nach dem Docker Bild erstellt wird, weil es von einer Apache Mesos Aufgabe gesetzt wird. Für meine Zwecke muss ich den Docker-Container (vom Marathon) im Host-Modus, nicht im Bridge-Modus ausführen.

--- Edit 2 ---

ich die Dinge geändert nur auf mein Hauptproblem zu konzentrieren. Die Docker Datei hat jetzt nur noch die am Ende angefügt folgende:

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

Und start-tomcat.sh:

#!/bin/bash 
catalina.sh run 

Noch kein Glück.

Antwort

2

Update: Damit der "catalina.sh run" mit einer ungültigen Option fehlschlägt, überprüfen Sie zuerst die Zeilenumbrüche von einem Windows-System. Sie verursachen Fehler, wenn das Shell-Skript in einer Linux-Umgebung gelesen wird.


bei catalina.sh Sehen, ich glaube, Sie CATALINA_OPTS wollen, nicht 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. 
+0

Ich kann sehen, wie das etwas auf der ganzen Linie zu beheben wäre, aber das Problem besteht nach wie vor, auch wenn ich nicht‘ t stören Einstellung OPTS überhaupt (siehe Edit 2). –

+0

Ändern Sie diese start-tomcat.sh auf einer Windows-Maschine? Erste Schätzung wäre ein Windows-Zeilenvorschub in der Datei. Darüber hinaus würde es hilfreich sein, die "FROM" -Zeile zu sehen, die Sie in Ihrer Docker-Datei verwenden, um einzugrenzen, welche Version von catalina.sh Sie verwenden, oder diese Datei einzuschließen, wenn Sie Änderungen vorgenommen haben. – BMitch

+0

Die ursprüngliche Version der Datei wurde in Windows erstellt. Ich habe es total vergessen, weil ich die Datei in Nano bearbeitet habe. Das hat es behoben.Ich kann dies als die richtige Antwort markieren, es sei denn, Sie möchten eine andere Antwort geben. –

Verwandte Themen