itsbehind itsbehind - 1 year ago 361
Bash Question

Alpine linux in docker container ignoring shell script arguments

I'm trying to create a docker image which sets a custom tomcat port (I know you can set an external port with the docker flag "-p 8888:8080" but for my use case I want to change the internal port as well).

When I try to start the run argument is being ignored for some reason.


# Tomcat 8 alpine dockerfile copied here (URL below)... minus the CMD line at the end

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

The tomcat file, server.xml, is the same as the default except for the line:

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

export JAVA_OPTS=-Dport.http.nonssl=${PORT} run

The image builds successfully, but when I run with

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

I just get a list of commands as if I didn't give it an argument. I've also tried

/usr/local/tomcat/bin/ run

sh -c " run"

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

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

I'm pretty sure I'm missing something simple here. I'd guess it has something to do with the syntax, but maybe it has something to do with docker or alpine that I'm not aware of. This is my first time using alpine linux.

---Edit 1---

To explain my use case... I'm setting PORT after the docker image is created because it's being set by an apache mesos task. For my purposes I need to run the docker container (from marathon) in host mode, not bridged mode.

---Edit 2---

I modified things to only focus on my main issue. The docker file now only has the following appended to the end:

RUN chmod +x /
ENTRYPOINT ["/bin/sh","/"]


#!/bin/bash run

Still no luck.

Answer Source

Update: for the " run" to fail with an invalid option, first check for linefeeds from a Windows system. They'll cause errors when the shell script is read in a Linux environment.

Looking at, I believe you want CATALINA_OPTS, not 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
# 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 (  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.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download