Page History
...
- Users can build their own Docker images for JOC Cockpit.
- This article explains options how to create the JOC Cockpit image.
Dockerfile
Docker images for JS7 JOC Cockpit provided by SOS make use of the following Dockerfile:
Build Environment
For the build environment the following directory hierarchy is assumed:
js7-joc
build.sh
build
Dockerfile
start-joc.sh
config
The root directory js7-joc
could have any name. Consider that below build script by default will use the directory name to determine the resulting image name.
The build script build.sh
and JOC Cockpit start script start-joc.sh
are explained below.
Dockerfile
Docker images for JS7 JOC Cockpit provided by SOS make use of the following Dockerfile:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
FROM openjdk:8-jre
LABEL maintainer="Software- und Organisations-Service GmbH"
# BUILD | ||||||||
Code Block | ||||||||
| ||||||||
FROM openjdk:8-jre LABEL maintainer="Software- und Organisations-Service GmbH" # BUILD SETTINGS # provide build arguments for release information ARG JS_MAJORRELEASE ARG JS_RELEASE_MAJOR # default user id has to match later run-time user ARG JS_USER_ID=${JS_USER_ID:-1001} ARG JS_HTTP_PORT=${JS_HTTP_PORT:-4446} ARG JS_HTTPS_PORT=${JS_HTTPS_PORT:-4443} ARG JS_JAVA_OPTIONS=${JS_JAVA_OPTIONS} # RUN-TIME SETTINGS # JS7 JobScheduler ports and Java options ENV RUN_JS_HTTP_PORT=${RUN_JS_HTTP_PORT:-$JS_HTTP_PORT} ENV RUN_JS_HTTPS_PORT=${RUN_JS_HTTPS_PORT:-$JS_HTTPS_PORT} ENV RUN_JS_JAVA_OPTIONS=${RUN_JS_JAVA_OPTIONS:-$JS_JAVA_OPTIONS} # PREPARATION # install process tools, bash RUN apt-get update && \ apt-get install -y procps && \ apt-get install -y bash # add installer tarball # ADD https://download.sos-berlin.com/JobScheduler.${JS_RELEASE_MAJOR}/js7_joc_linux.${JS_RELEASE}.tar.gz /usr/local/src/ # COPY js7_joc_linux.${JS_RELEASE}.tar.gz /usr/local/src/ # INSTALLATION # extract installer tarball # for JDK < 12, /dev/random does not provide sufficient entropy, see https://kb.sos-berlin.com/x/lIM3 RUN test -e /usr/local/src/js7_joc_linux.${JS_RELEASE}.tar.gz && \ tar zxvf /usr/local/src/js7_joc_linux.${JS_RELEASE}.tar.gz -C /usr/local/src/ && \ rm -f /usr/local/src/js7_joc_linux.${JS_RELEASE}.tar.gz && \ ln -s /usr/local/src/joc.${JS_RELEASE} /usr/local/src/joc && \ sed -i 's/securerandom.source=file:\/dev\/random/securerandom.source=file:\/dev\/urandom/g' /usr/local/openjdk-8/lib/security/java.security # copy installer response file, hibernate configuration file and start script COPY joc_install.xml /usr/local/src/joc/ COPY hibernate.cfg.xml /usr/local/src/joc/ COPY start-joc.sh /usr/local/bin/ # perform installation, andadd make defaultjobscheduler user the owner of directorieaccount RUN groupadd --gid ${JS_USER_ID:-1001} jobscheduler && \ useradd --uid ${JS_USER_ID:-1001} --gid jobscheduler --home-dir /home/jobscheduler --no-create-home --shell /bin/bash jobscheduler && \ cd /usr/local/src/joc && ./setup.sh -u joc_install.xml && \ chownchmod -R jobscheduler:jobscheduler /var/sos-berlin.com && \ chmod +x /usr/local/+x /usr/local/bin/start-joc.sh # CONFIGURATION # security:enable https and certificatesmodule RUN java -jar "/opt/sos-berlin.com/js7/joc/jetty/start.jar" -Djetty.home="/opt/sos-berlin.com/js7/joc/jetty" -Djetty.base="/var/sos-berlin.com/js7/joc" --add-to-start=https # add keystore and truststore for private keys and certificates COPY https-keystore.p12 /var/sos-berlin.com/js7/joc/resources/joc/ COPY https-truststore.p12 /var/sos-berlin.com/js7/joc/resources/joc/ COPY# start.ini.add /tmpadd keystore and truststore locations to configuration files COPY start.ini.add /tmp/ COPY joc.properties.add /tmp/ RUN cat /tmp/start.ini.add >> /var/sos-berlin.com/js7/joc/start.ini && \ cat /tmp/joc.properties.add >> /var/sos-berlin.com/js7/joc/resources/joc/joc.properties # copy configuration COPY config/ /var/sos-berlin.com/js7/joc/resources/ # make jobscheduler user account the owner of directories RUN chown -R jobscheduler:jobscheduler /var/sos-berlin.com # CODA # allow incoming traffic to portports EXPOSE $RUN_JS_HTTP_PORT $RUN_JS_HTTPS_PORT # run-time user, can be overwritten when running the container USER jobscheduler CMD ["sh","-c","/usr/local/bin/start-joc.sh --java-options=\"$RUN_JS_JAVA_OPTIONS\""] |
Build Script
The build script offers a number of options to parameterize the Dockerfile:
...
language | bash |
---|---|
title | Build Script for JOC Cockpit Image |
linenumbers | true |
collapse | true |
...
Explanations:
- Line 1: The base image is OpenJDK Java 1.8 (Debian based). You can run JOC Cockpit with newer Java releases, however, stick to Oracle, OpenJDK or AdoptOpenJDK as the source for your Java base image. Alternatively you can use your own base image and install Java 1.8 on top of this. Consider that availability of JDBC Drivers can limit the Java version to be used.
- Line 8 - 9: The release identification is injected by build arguments. This information is used to determine the tarball to be downloaded.
- Line 12 - 15: Defaults for the user id running the JOC Cockpit inside the container as well as HTTP and HTTPS ports are provided. These values can be overwritten by providing the respective build arguments.
- Line 20 - 22: Environment variables are provided at run-time, not at build-time. They can be used to specify ports and Java options when running the container.
- Line 36 - 37: You can either download the JOC Cockpit tarball directly from the SOS web site or you store the tarball with the build directory and copy from this location.
- Line 51: if a
config
folder is available in the build directory then its contents is copied to the respectiveconfig
folder in the container. This can be useful to create an image with individual settings in configuration files, see JS7 - JOC Cockpit Configuration Items. Line 54: The
start-joc.sh
script is copied from the build directory to the container. Users can apply their own version of the start script. The start script used by SOS looks like this:Code Block language bash title JOC Cockpit Start Script linenumbers true collapse true #!/bin/sh js_java_options="" for option in "$@" do case "$option" in --
...
java-
...
options=*)
...
js_java_options=`echo "$option" | sed 's/--
...
java-
...
options=//'` ;;
...
*)
...
echo "unknown argument: $option" exit 1
...
...
...
...
...
...
...
;; esac done if [ ! -z "$js_java_options" ] then export JAVA_OPTIONS="${JAVA_OPTIONS} $js_java_options" fi echo "starting JOC Cockpit: /opt/sos-berlin.com/js7/joc/jetty/bin/jetty.sh start" /opt/sos-berlin.com/js7/joc/jetty/bin/jetty.sh start && tail -f /dev/null
- Line 57 - 58: The user account
jobscheduler
is created and is assigned the user id and group id handed over by the respective build arguments. This translates to the fact that the account running the JOC Cockpit inside the container and the account that starts the container are assigned the same user id and group id. This allows the account running the container to access any files created by the JOC Cockpit in mounted volumes with identical permissions. - Line 67: The HTTP port and optionally the HTTPS port are exposed to the Docker host. Both ports can be forwarded by environment variables when running the container, overwriting the build-time values. This is relevant only if users want to use ports inside the container that are different from the default values. In most situations the default ports should be fine and are mapped to outside ports on the Docker host when starting the container.
- Line 69: The start script is executed and is dynamically parameterized from environment variables that are forwarded when starting the container.
Build Script
The build script offers a number of options to parameterize the Dockerfile:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
#!/bin/sh set -e SCRIPT_HOME=$(dirname "$0") SCRIPT_HOME="`cd "${SCRIPT_HOME}" >/dev/null && pwd`" SCRIPT_FOLDER="`basename $(dirname "$SCRIPT_HOME")`" # ----- modify defalt settings ----- JS_RELEASE="2.0.0-SNAPSHOT" JS_REPOSITORY="sosberlin/js7" JS_IMAGE="$(basename "${SCRIPT_HOME}")-${JS_RELEASE//\./-}" JS_USER_ID="$UID" JS_NETWORK="js7" JS_HTTP_PORT="4446" JS_HTTPS_PORT="4443" JS_DBMS_HOST="dbms_host" JS_DBMS_IP=`hostname -I | cut -d' ' -f1` JS_JAVA_OPTIONS="-Xmx128m" JS_BUILD_ARGS="" # ----- modify default settings ----- for option in "$@" do case "$option" in --release=*) JS_RELEASE=`echo "$option" | sed 's/--release=//'` --http-port=*) JS_HTTP_PORT=`echo "$option" | sed 's/--http-port=//'` ;; --https-port=*) JS_HTTPS_PORT=`echo "$option" | sed 's/--https-port=//'` ;; --java-options=*) JS_JAVA_OPTIONS=`echo "$option" | sed 's/--java-options=//'` ;; --build-args=*) JS_BUILD_ARGS=`echo "$option" | sed 's/--build-args=//'` ;; *) echo "unknown argument: $option" exit 1 ;; --repository=*) JS_REPOSITORY=`echo "$option" | sed 's/--repository=//'` ;; esac done JS_MAJOR="${JS_MAJOR:-$JS_MAJOR_DEFAULT}" JS_RELEASE="${JS_RELEASE:-$JS_RELEASE_DEFAULT}" JS --image=*) JS_IMAGE=`echo "$option" | sed 's/--image=//'` ;; --user-id=*) JS_USER_ID="${JS_USER_ID:-$JS_USER_ID_DEFAULT}" JS_NETWORK="${JS_NETWORK:-$JS_NETWORK_DEFAULT}" JS_HTTP_PORT="${JS_HTTP_PORT:-$JS_HTTP_PORT_DEFAULT}" JS_HTTPS_PORT="${JS_HTTPS_PORT:-$JS_HTTPS_PORT_DEFAULT}" JS_DBMS_HOST="${JS_DBMS_HOST:-$JS_DBMS_HOST_DEFAULT}" JS_DBMS_IP="${JS_DBMS_IP:-$JS_DBMS_IP_DEFAULT}" JS_JAVA_OPTIONS="${JS_JAVA_OPTIONS:-$JS_JAVA_OPTIONS_DEFAULT}" JS_BUILD_ARGS="${JS_BUILD_ARGS:-$JS_BUILD_ARGS_DEFAULT}" set -x docker build --no-cache --rm \ --tag=$REPOSITORY_NAME:$IMAGE_NAME \ --file=$SCRIPT_HOME/build/Dockerfile \ --network=$JS_NETWORK \ `echo "$option" | sed 's/--user-id=//'` ;; --network=*) JS_NETWORK=`echo "$option" | sed 's/--network=//'` ;; --http-port=*) JS_HTTP_PORT=`echo "$option" | sed 's/--http-port=//'` ;; --addhttps-host=$JS_DBMS_HOST:$JS_DBMS_IP \ --build-arg="JS_MAJOR=$JS_MAJOR" \ port=*) JS_HTTPS_PORT=`echo "$option" | sed 's/--https-port=//'` --build-arg="JS_RELEASE=$JS_RELEASE" \ --build-arg="JS_USER_ID=$JS_USER_ID" \ ;; --builddbms-arg="host=*) JS_HTTPDBMS_PORT=$JS_HTTP_PORT" \ --build-arg="JS_HTTPS_PORT=$JS_HTTPS_PORT" \ --build-arg="JS_JAVA_OPTIONS=$JS_JAVA_OPTIONS" \ $JS_BUILD_ARGS $SCRIPT_HOME/build set +x |
Explanations:
HOST=`echo "$option" | sed 's/--dbms-host=//'`
;;
--dbms-ip=*) JS_DBMS_IP=`echo "$option" | sed 's/--dbms-ip=//'`
;;
--java-options=*) JS_JAVA_OPTIONS=`echo "$option" | sed 's/--java-options=//'`
;;
--build-args=*) JS_BUILD_ARGS=`echo "$option" | sed 's/--build-args=//'`
;;
*) echo "unknown argument: $option"
exit 1
;;
esac
done
set -x
docker build --no-cache --rm \
--tag=$JS_REPOSITORY:$JS_IMAGE \
--file=$SCRIPT_HOME/build/Dockerfile \
--network=$JS_NETWORK \
--add-host=$JS_DBMS_HOST:$JS_DBMS_IP \
--build-arg="JS_RELEASE=$JS_RELEASE" \
--build-arg="JS_RELEASE_MAJOR=$(echo $JS_RELEASE | cut -d . -f 1,2)" \
--build-arg="JS_USER_ID=$JS_USER_ID" \
--build-arg="JS_HTTP_PORT=$JS_HTTP_PORT" \
--build-arg="JS_HTTPS_PORT=$JS_HTTPS_PORT" \
--build-arg="JS_JAVA_OPTIONS=$JS_JAVA_OPTIONS" \
$JS_BUILD_ARGS $SCRIPT_HOME/build
set +x |
Explanations:
- Line 12 - 22: Default values are specified that are used if no command line arguments are provided. This includes values for
- the release number: adjust this value to a current release of JS7.
- the repository which by default is
sosberlin:js7
. - the image name is determined from the current folder name and the release number.
- the user id is by default the user id of the user running the build script.
- the Docker network: the build script assumes a Docker network to be used for which a name is specified.
- the HTTP port and HTTPS port: if the respective port is not specified then the JOC Cockpit will not listen to a port for the respective protocol. You can for example disable the HTTP protocol by specifying an empty value. The default ports should be fine as they are mapped by the run script to outside ports on the Docker host. However, you can modify ports as you like.
- Java options: typically you would specify default values e.g. for Java memory consumption. The Java options can be overwritten by the run script when starting the container, however, you might want to create your own image with adjusted default values.
- Line 27 - 52: The above options can be overwritten by command line arguments like this:
Code Block language bash title Running the Build Script with Arguments linenumbers true ./build.sh --network=js --http-port=14445 --https-port=14443 --java-options="-Xmx1G"
- Line 56 - 66: The effective
docker build
command is executed with arguments. The Dockerfile is assumed to be located with thebuild
sub-directory of the current directory.Status colour Yellow title TBD