Docker nginx/dropwizard with Travis CI


Update: Can’t recommend using Travis for this kind of CI, it turned out very flakey once I used actual images rather than the simple echo tool images. Builds would sometimes timeout after 15mins of hanging, either on building images or attaching. Not sure why, but I imagine Travis isn’t really intended for loading multiple containers ~400meg in size (JVM+deps).

Example using Docker to create an nginx image and dropwizard image, then link them together so nginx acts as a reverse proxy for Dropwizard. Can be extended to link together multiple Dropwizard applications. Uses Docker Compose to create and configure the images.

terminal gif


To run locally:

gradle run
# ./go

To run containers:

gradle buildJar
docker-compose up -d

# retrieve your docker host IP from boot2docker
boot2docker ip

# curl dropwizard/nginx containers using docker host IP


The docker-compose.yml file configures the two images, creating a dropwizard container and linking it to an nginx container. With the link in place, docker creates a hosts entry for the dropwizard container which can be used in the nginx config volumes-nginx-conf.d/default.conf when setting up the reverse proxy.

Based Travis build on moul/travis-docker.

Using a client image to test the nginx/dropwizard images, as you cannot curl directly from Travis CI. Ideally, once Travis has started the containers in demonised form I would run a test script which uses curl/selenium to test the various endpoints exposed from nginx and hit dropwizard. If this needs to be done via the client then the results of the test can be output to a write-enabled volume and parsed to determine build result, as docker-compose will always return exit code 0 if the containers run.

Docker Dropwizard image

Made an example Docker image for running a Dropwizard Application in a container.


terminal gif


To run locally:

gradle run
# ./go

To build docker image:

gradle dockerBuildImage
# ./ (requires oneJar task to build dropwizard application)

To run docker image:

gradle dockerRunImage
./ (requires built image)

When image is running use boot2docker ip to get the docker IP and docker ps to see the port assigned to the container port 8080, then curl http://<dockerip&gt;:<port>/hello to call the dropwizard application running in the container.

If using LINUX you can use localhost and have to sudo docker commands.


This is a bare bones example for building an image for running a single Dropwizard application. It uses the standard docker java:jre-8 image as base, copies necessary files into image folder/opt/dropwizard and runs command to start dropwizard application.


FROM java:8-jre
COPY config.yml /opt/dropwizard/
COPY build/libs/docker-dropwizard-application-standalone.jar /opt/dropwizard/
WORKDIR /opt/dropwizard
CMD ["java", "-jar", "-Done-jar.silent=true", "docker-dropwizard-application-standalone.jar", "server", "config.yml"]


This is a simple way of defining a disposal container for a dropwizard application, taking effort away from operations and making the development team responsible for how their application will be hosted and run. Your application will be completely isolated from other parts of your solution running on the same host machine, including other instances of the same application for scaling and redundancy.

Instead of thinking of instances of your application, you have instances of your container image, hosted on one or more docker hosts depending on your architecture. Used correctly, you can create container instances as needed, kill when done, using versioning of images to release new versions of the service.

Things to consider:

  • How to extract information from running container instance application (logging, performance monitoring etc.)
  • Port management, how to create new containers with dynamic port allocation (to avoid collisions) while still balancing load between them
  • General release management using Docker
  • Configuration can be controlled by mounting configuration files to the container from the host rather than copying or adding them into the image (configuration per container instance rather than per image)

Docker Java 8 Helloworld

Example Docker image that when echos “Hello world!” when run.


terminal gif

Image has JRE rather than JDK to limit installed components. Tested on Mac using Boot2Docker(v1.5.0).


To run:

# compile class

# build image
docker build -t java8-helloworld .

# run image
docker run -it --rm --name my-running-app java8-helloworld