diff --git a/Dockerfile b/Dockerfile index 2f0c8d5..6d945cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,21 @@ -FROM anapsix/alpine-java:8 -MAINTAINER sscaling +FROM openjdk:8-jre -RUN apk update && apk upgrade && apk --update add curl && rm -rf /tmp/* /var/cache/apk/* +ARG buildversion=0.14.0 +ARG buildjar=jmx_prometheus_httpserver-$buildversion-jar-with-dependencies.jar -ENV VERSION 0.12.0 -ENV JAR jmx_prometheus_httpserver-$VERSION-jar-with-dependencies.jar - -RUN curl --insecure -L https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_amd64 -o usr/local/bin/dumb-init && chmod +x /usr/local/bin/dumb-init +ENV version $buildversion +ENV jar $buildjar +ENV SERVICE_PORT 5556 +ENV CONFIG_YML /opt/jmx_exporter/config.yml +ENV JVM_OPTS -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=5555 RUN mkdir -p /opt/jmx_exporter -RUN curl -L https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_httpserver/$VERSION/$JAR -o /opt/jmx_exporter/$JAR -COPY start.sh /opt/jmx_exporter/ +RUN useradd -ms /bin/bash prom_exporter +RUN chown prom_exporter:prom_exporter /opt/jmx_exporter + +USER prom_exporter + +RUN curl -L https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_httpserver/$version/$jar -o /opt/jmx_exporter/$jar COPY config.yml /opt/jmx_exporter/ -CMD ["usr/local/bin/dumb-init", "/opt/jmx_exporter/start.sh"] +CMD ["sh", "-c", "java $JVM_OPTS -jar /opt/jmx_exporter/$jar $SERVICE_PORT $CONFIG_YML" ] \ No newline at end of file diff --git a/README.md b/README.md index 093451b..0b25d85 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,29 @@ -[![Build status](https://travis-ci.com/sscaling/docker-jmx-prometheus-exporter.svg?branch=master)](https://travis-ci.com/sscaling/docker-jmx-prometheus-exporter) [![Docker Pulls](https://img.shields.io/docker/pulls/sscaling/jmx-prometheus-exporter.svg)](https://hub.docker.com/r/sscaling/jmx-prometheus-exporter) - Docker JMX exporter for Prometheus ================================== Essentially another dockerised JMX Exporter image, this uses alpine-java and dumb-init to provide a relatively small image (approx 130Mb) and includes a released version of jmx_exporter from the [maven central repository](https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_httpserver/) -Available on [Docker hub](https://hub.docker.com/r/sscaling/jmx-prometheus-exporter/) +Available on [Docker hub](https://hub.docker.com/r/reasland/jmx-prometheus-exporter/) Building docker image --------------------- ``` -docker build -t sscaling/jmx-prometheus-exporter . +docker build -t reasland/jmx-prometheus-exporter . ``` +### Build Arguments + +Additionally, the following build arguments can be defined + +- version - default 0.14.0 - what version of the jmx_exporter http server to use (if you are going to docker push, please tag prom_jmx:$VERSION) +- jar - default jmx_prometheus_httpserver-$VERSION-jar-with-dependencies.jar - what jar file from the maven repo https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_httpserver/ to use + Running ------- ``` -docker run --rm -p "5556:5556" sscaling/jmx-prometheus-exporter +docker run --rm -p "5556:5556" reasland/jmx-prometheus-exporter ``` Then you can visit the metrics endpoint: [http://127.0.0.1:5556/metrics](http://127.0.0.1:5556/metrics) (assuming docker is running on localhost) @@ -29,7 +34,7 @@ Configuration By default, the jmx-exporter is configured to monitor it's own metrics (as per the main repo example). However, to provide your own configuration, mount the YAML file as a volume ``` -docker run --rm -p "5556:5556" -v "$PWD/config.yml:/opt/jmx_exporter/config.yml" sscaling/jmx-prometheus-exporter +docker run --rm -p "5556:5556" -v "$PWD/config.yml:/opt/jmx_exporter/config.yml" reasland/jmx-prometheus-exporter ``` The configuration options are documented: [https://github.com/prometheus/jmx_exporter](https://github.com/prometheus/jmx_exporter) diff --git a/docker_push b/docker_push index 4fd3736..e2d18a8 100755 --- a/docker_push +++ b/docker_push @@ -1,6 +1,6 @@ #!/bin/bash -e -BASE_IMAGE="sscaling/jmx-prometheus-exporter" +BASE_IMAGE="reasland/jmx-prometheus-exporter" IMAGE_VERSION="$1" if [ -z "$IMAGE_VERSION" ]; then diff --git a/start.sh b/start.sh deleted file mode 100755 index 537bd54..0000000 --- a/start.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -if [ -z "$SERVICE_PORT" ]; then - SERVICE_PORT=5556 -fi - -if [ -z "$JVM_OPTS" ]; then - JVM_OPTS="-Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=5555" -fi - -if [ -z "$CONFIG_YML" ]; then - CONFIG_YML=/opt/jmx_exporter/config.yml -fi - -java $JVM_OPTS -jar /opt/jmx_exporter/jmx_prometheus_httpserver-$VERSION-jar-with-dependencies.jar $SERVICE_PORT $CONFIG_YML