Running Glassfish Application Server in a Docker container

glassfish-logoDocker ( is getting a lot of attention lately – it provides a container (sort of lightweight virtual machine) that makes a clean separation from the rest of the operating system. In this container you can run any application and because you can tightly control the contents of the container, you can create a predictable and repeatable environment for your application.

Although the trend seems to go to standalone Java applications, you can also run a Java (JEE) application server in a docker container. Since I work a lot with the Glassfish application server, I gave it a try in a Docker container by “dockerizing” Glassfish 4.1 into a Docker image.

I created a base image with Ubuntu 14.04 with Oracle JDK 8 and used this to create an image with Glassfish 4.1. I took an existing Docker image definition from Github ( and made some modifications to make it easier to configure the application server. My resulting Docker source is on Github:

After building the image, you can run it:

docker run -d -p 4848:4848 -p 8080:8080 -e GLASSFISH_PASS="mypass" koert/glassfish-4.1

This will set the admin password to “mypass” and make the 4848 and 8080 port accessable on the host. You just open https://localhost:4848 in your browser and you can deploy an application. I deployed the Primefaces showcase ( and it runs great.

The nice thing thing about the Docker container is that you can stop the container and start a fresh one within seconds. No matter how you mess up the Glassfish configuration, you can throw it way (or restart it) quickly.