Sign inSign up

rusnyder/docker-dropwizard

By rusnyder

•Updated over 8 years ago

Base image for building and running Dropwizard applications in Docker

Image
0

588

rusnyder/docker-dropwizard repository overview

⁠Docker Dropwizard

Travis CI Docker Hub License

A Docker base image for building and running Dropwizard applications in Docker.

The aim of this project is to solve a specific problem:

  • I've got a Dropwizard application I want to package up to run in Docker
  • I'd like the image I produce to be configurable via "standard" Docker mechanisms (i.e. - build args and environment variables)
  • I'd like to do so without adding any libraries to my runtime

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.

⁠Quickstart

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

  1. 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"]
    
  2. 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 %}
    
  3. 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>
    
  4. 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
    

⁠Configuration Templating

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.

⁠Base Dropwizard Config

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 VarSupportDescriptionDefault
DW_APP_PORT:heavy_check_mark:Port for app server to bind8080
DW_ADMIN_PORT:heavy_check_mark:Port for admin server to bind8081
DW_BIND_HOST:heavy_check_mark:Host to bind all servers to127.0.0.1
DW_ENABLE_SSLlimitedSet to true to enable SSL configsfalse

Logging

Env VarSupportDescriptionDefault
DW_LOG_LEVEL:heavy_check_mark:Base level for app logINFO
DW_LOG_TZ:heavy_check_mark:Timezone for app logUTC

⁠Authors

Tag summary

Content type

Image

Digest

Size

220.9 MB

Last updated

over 8 years ago

docker pull rusnyder/docker-dropwizard:8-jre