I’m pleased to announce that a pre-built Docker image containing IBM WebSphere Application Server for Developers V8.5.5 Liberty Profile and the IBM Java Runtime Environment 7.1 SR1 is now available on Docker Hub. This allows you to get the lightweight Liberty server up and running quickly in your Docker environment with only a single command.
For those not aware, Docker builds on Linux containerization and a layered file system to provide a mechanism for building and running lightweight and portable application containers. Docker Hub is a central repository for sharing base images which can be rapidly customized and composed.
Docker can be installed natively on Linux distributions or via the Boot2Docker virtual image on other platforms using the instructions from the Docker website. Once installed, getting a running Liberty server is as simple as executing:
id=$(docker run -d -e LICENSE=accept -p 80:9080 websphere-liberty)
On first invocation, this will pull down the image from Docker Hub. The
-d option then indicates that the container should be started in detached mode i.e. in the background, the LICENSE environment variable indicates that you accept the terms of the Liberty and JRE licenses, and the HTTP port exposed by the image on port 9080 is mapped to port 80 on the host. The command returns the identifier for the container which we store in a variable.
If you’re quick (and it only takes seconds for the container and then Liberty to start), you can watch the container logs as the server starts using:
docker logs --tail=all -f $id
Once the server is started, you can browse to
http://localhost:80 on the host running Docker and you should see the Liberty welcome page. (Tip: if you’re using Boot2Docker you’ll probably want to expose port 80 from the Boot2Docker virtual image to your machine so that you can use a browser there.)
Finally, to kill the container, use the following command:
docker kill $id
If you execute these commands again, the run command will now return almost instantaneously as the image and its associated layers is now cached locally.
A server with no application is of limited interest though. As covered in the usage information, there are multiple ways to run an application using this image and we will consider just two of them here. Firstly, as the image contains a default server configuration that specifies the
webProfile-6.0 feature, if we have a simple web application on our host (
/tmp/myApp.war in this example) we can simply mount that to the
dropins directory of the server configuration when starting the container:
id=$(docker run -d -e LICENSE=accept -p 80:9080 \ -v /tmp/myApp.war:/opt/ibm/wlp/usr/servers/defaultServer/dropins/myApp.war \ websphere-liberty)
Once the server has started, you will find the application running at http://localhost:80/myApp.
In the second example, we imagine an application that uses a feature that is not available in the the default runtime installation. We will therefore build a new image, based on the one from Docker Hub, which adds the required feature (JMS in this scenario) from the online Liberty repository. We will also add a new server.xml and the application as part of the image using a Dockerfile that looks as follows:
FROM websphere-liberty RUN featureManager install jms-1.1 --when-file-exists=ignore -acceptLicense COPY server.xml /opt/ibm/wlp/usr/servers/defaultServer/ COPY myApp.war /opt/ibm/wlp/usr/servers/defaultServer/dropins/ ENV LICENSE accept
You will also see that we have chosen to accept the Liberty and JRE licenses as part of building this new layer. From the same directory as the Dockerfile, we can then build an image tagged
app using the following command:
docker build -t app .
That image can then be run as follows:
docker run -d -p 80:9080 app
You can run this command multiple times mapping to different ports on the host to run multiple instances of the application. Each of these instances is sharing the same image layers thereby saving space on disk and in memory.
We have only scratched the surface of what is possible with Liberty and Docker here but I hope that this article has whet your appetite for more! If you experience any problems with the image, raise an issue on GitHub where you can find the source Dockerfile for the image or, for more general questions, post to dW Answers in the WASdev space.
Update 2015-01-28: The Docker image for the Liberty Profile has now graduated to become an official repository. This post has been updated to reflect that you should now pull the image as “websphere-liberty” rather than “wasdev/websphere-liberty”.