Base image for building and running Dropwizard applications in Docker
588
A Docker base image for building and running Dropwizard applications in Docker.
The aim of this project is to solve a specific problem:
The base image provides facilities for templating your Dropwizard config file without adding any runtime dependencies, since the config processing is handled out-of-process.
The best way to use this project is as a base image for your Docker builds. This example is based off of an uberjar build for your Dropwizard project, but you can copy all of the dependencies directly to a container and set the classpath instead (see: Basic Classpath Integration Test)
NOTE: This project is JUST a Docker base image and can thusly be used however you please; the Quickstart is just a complete (yet opinionated) example of how to effectively integrate the base image into your Dropwizard project
Add a dockerfile to your Dropwizard project
# file: Dockerfile
FROM rusnyder/docker-dropwizard:8-jre-alpine
# Copy the DW uberjar, and set it to be run directly
ARG JAR_FILE
COPY target/${JAR_FILE} /${JAR_FILE}
ENV DW_UBERJAR=/${JAR_FILE}
# Copy the config template
ARG CONFIG_TEMPLATE
COPY ${CONFIG_TEMPLATE} /${CONFIG_TEMPLATE}
ENV DW_CONFIG_TEMPLATE=/${CONFIG_TEMPLATE}
# Run the "server" command (optional; 'server' is the default)
CMD ["server"]
Create a config template for your application (NOTE: docker-dropwizard uses Jinjava for templating, and feeds all environment variables in as Jinjava variables.)
# file: src/docker/foobar-config.yml
# A base config ships with docker-dropwizard that can be used to bootstrap
# common Dropwizard configs using exactly this line:
{% include "base-dw-config.yml" %}
# Add any additional config, optionally using Jinjava expressions
foobar:
someConfig: hello
moreConfig: {{ SOME_MORE_CONFIG }}
# Jinjava tags are also supported
{% if SOME_ENABLE_BAR_BAZ_FLAG %}
bar: baz
{% endif %}
Add a Dockerfile Maven plugin configuration to your build, setting the build args from the Dockerfile above. (NOTE: you can build the image using whatever plugins or tooling that you want, this is just an example)
<!-- file: pom.xml -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>${dockerfile-maven-version}</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>rusnyder/foobar</repository>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
<CONFIG_TEMPLATE>src/docker/foobar-config.yml</CONFIG_TEMPLATE>
</buildArgs>
</configuration>
</plugin>
Build your project
# The 'build' goal will create your docker image during the 'package' phase
mvn clean package
# The 'push' goal can push your image to your docker repository during the
# 'deploy' phase, assuming you had a repo and credentials configured as-per
# the Dockerfile Maven documentation
mvn deploy
The built image will (optionally) process a provided configuration template at
docker run time to allow your containers to be portable and configurable.
Templates are rendered using Jinjava which provides a nearly-complete subset of the Jinja2 templating language.
To save the hassle of having to define a template for all of the boilerplate Dropwizard configuration, a partial template is provided that you can include at the beginning of your config template:
{% include "base-dw-config.yml %}
This handles the majority of common Dropwizard configuration, and exposes many environment variables for container configuratioon:
Server
| Env Var | Support | Description | Default |
|---|---|---|---|
| DW_APP_PORT | :heavy_check_mark: | Port for app server to bind | 8080 |
| DW_ADMIN_PORT | :heavy_check_mark: | Port for admin server to bind | 8081 |
| DW_BIND_HOST | :heavy_check_mark: | Host to bind all servers to | 127.0.0.1 |
| DW_ENABLE_SSL | limited | Set to true to enable SSL configs | false |
Logging
| Env Var | Support | Description | Default |
|---|---|---|---|
| DW_LOG_LEVEL | :heavy_check_mark: | Base level for app log | INFO |
| DW_LOG_TZ | :heavy_check_mark: | Timezone for app log | UTC |
Content type
Image
Digest
Size
220.9 MB
Last updated
over 8 years ago
docker pull rusnyder/docker-dropwizard:8-jre