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”.

17 Comments on "Announcing: Liberty profile on Docker Hub"

  1. Tomas Kramaric December 01, 2016

    I run my app in docker wlp using your command, however when i navigate my browser to http://localhost:80/myApp its not working. any ideas ?

  2. […] the end of last year the Liberty profile is on Docker Hub. The Liberty Profile image is supplied for IBM Containers. You can use this image […]

  3. Kevin Mayfield October 19, 2015

    Each “docker run” will create a new container. This won’t take up much space, but it annoying to clean up later unless you want to remove everything that is not running (docker rm `docker ps -aq`).

    Once you have a container, the next time you need the liberty service, you can just start the previous container with its ID, or the name you specified when you did the initial ‘run’ (–name myliberty):

    docker start myliberty

    • David Currie October 19, 2015

      Thanks for commenting Kevin. My personal preference is to always use ‘run’ as you can be sure that you’re not accumulating state in the container even if it does mean the occasional housekeeping of stopped images. Also remember that for containers that you’re running in the foreground you can use the ‘–rm’ option to have them clean up when they terminate.

  4. If I am running Liberty in a docker container, and have configured it a member of a collective, what credentials are used to register the host? Liberty runs in the container typically under a username, but no password.

    • David Currie October 08, 2015

      Hi Mike – unless you have SSH in the container then registering it with the controller is not much use. You need the controller to be Docker aware so that it knows that, for example, starting a server is something it should achieve by starting a container (the work that is ongoing in the beta). At that point, the host that you register will likely be the Docker host, not the container.

      Regards,
      David

  5. […] The September 2015 Liberty Beta includes a preview of management function for Liberty Docker containers. A Liberty Docker container is a Liberty Server packaged and deployed through a Docker image. New in this beta is collective management for these containers. This is a continuation of Liberty’s embrace of Docker, which started with the publishing of a Liberty Docker image on Docker Hub. […]

  6. QAUW_Ashwin_Radhakrishnan August 12, 2015

    I am new to Chef and Docker so I have very simple requirment

    Can I do configuration management for the WAS ND [Not only liberty profile but also WAS ND prior versions] using Docker or Chef?

    By Configuration management what I mean is for ex: WAS ND, would I be able to write a recipe which will do create/modify/delete JDBC data source/JMS Topic/Queue, Share library, Users modifications etc on a WASND instance without using Jython/JACL or any external scripts. The point is do update run time configurations for a product solely using Chef recipe or Chef calling Docker, if its possible kindly then let me know how.

  7. Richard Kent August 10, 2015

    The first command id=$(docker run –d -e LICENSE=accept –p 80:9080 websphere-liberty) has a strange character for the hyphen before the d and p, it is not actually a hyphen. This threw me at first and will affect people copying and pasting. Can you fix please? Thanks

    • David Currie August 24, 2015

      Thanks for pointing this out Richard – I’ll get this fixed. Let me know if you have any other comments/questions.

  8. […] released our image on Docker Hub back in December which can be pulled from the official repository […]

  9. […] Docker is probably the coolest and light weight virtualisation option for developers. It becomes more interesting, when put in the context of PaaS/Cloud Foundry. Even otherwise, an idea I was toying with was this : As developers, we tend to setup multiple dev tools and runtimes, to build things. Over a period of time, we tend to forget where all we have stuff installed and what all stuff to clean up if it comes to it. Docker is probably a great option, to have stuff running as containers – bringing the envs as needed and killing them as we are done with them. This could potentially keep our machines clean! And with the excellent docker registry support – there is nothing I couldn’t find off the list! So, one of my initial experiments was to get the docker up and running on my local machine (Mac OSX Maverics) and bring up a WebSphere Liberty container. Below are the steps I followed to get it working. Don’t miss the official references at the end! (1) Install Boot2Docker based VM (this is the only option – if you have an OS other than Linux. Check out the detailed steps on the Docker site : https://docs.docker.com/installation/mac/ (2) Once docker is setup. These are some useful commands : $boot2docker up (brings up the docker VM) $boot2docker down (shuts down the docker VM) $boot2docker delete (deletes the docker VM) $boot2docker init (re-builds the docker VM) init and delete were particularly useful. I did run into some issues while downloading some of the containers from the registry and doing a delete and init ensures that we have a clean image to start with again. (3) Pull the websphere-liberty docker image, following these steps : $docker pull websphere-liberty:8.5.5 Output : 511136ea3c5a: Pulling fs layer 511136ea3c5a: Download complete fa4fd76b09ce: Download complete 1c8294cc5160: Download complete 117ee323aaa9: Download complete 2d24f826cb16: Download complete aa3c1c2150cc: Download complete 3d6ca9f2162e: Download complete c020385b4c91: Download complete bcb5fe6787ce: Downloading 29.18 MB/95.65 MB 2m3s 15f1293dae42: Download complete bcb5fe6787ce: Download complete 206308eac8e6: Download complete 15f1293dae42: Download complete 2b6f5e03b544: Download complete 9fbf9d794a07: Download complete 109a0b626e6a: Download complete b572f225406d: Download complete 55767bfea810: Download complete 95a57445616d: Download complete 40621d772749: Download complete 65a2ded32d93: Download complete 49ef62f7a74c: Download complete e9ec83061a64: Download complete dc4e0620b516: Download complete c1fc1c4314a0: Download complete 8d9d3e3959db: Download complete Status: Downloaded newer image for websphere-liberty:8.5.5 (4) Once the liberty image is installed, follow this step, to run the liberty container (basically we instantiate the image as a docker container) $id=$(docker run -e LICENSE=accept -d -p 80:9080 websphere-liberty) After running the above, you can check if the server is up, by running : $docker logs –tail=all -f $id (5) Now that the server is running, its time to access the Liberty homepage. There are two options for this. One is sweet and short and the other a bit tedious (but worth knowing about) : (a) Short Option : Using the VM’s ip Run the following and note the ip of the boot2docker VM $boot2docker ip assuming the output was XYZ. Just run this URL on your host : http://XYZ:80 It should show you the Liberty page! (b) Long Option : Port forwarding To forward all incoming traffic from a specific host interface to the VM, specify the IP of that host interface like this: $VBoxManage modifyvm “boot2docker-vm” –natpf1 “guestssh,tcp,127.0.0.1,2222,,80″ This forwards all TCP traffic arriving on the localhost interface (127.0.0.1) via port 2222 to port 80 in the VM. Using this option, now you can access : http://localhost:2222 and you should see the liberty welcome page! To remove this forwarding rule again, use the following command: $VBoxManage modifyvm “VM name” –natpf1 delete “guestssh” Note : The VM should be shut down to perform the above long option. Otherwise you can explore using controlvm instead of modifyvm (refer the Virtual Box documentation) (6) At this point, I just created a default dynamic web project in my Eclipse – added a simple index.html under the WebContent folder. The idea was to deploy a war file from this project. Below are the steps, I followed to get it up and running on the liberty docker container : (a) First kill the running container (just did this – so we don’t have the common port issues) $docker ps -a (lists the containers running. Spot the container id) $docker kill <container id> (specify the container id and run the kill command) (b) Export the war file from eclipse and store it in a local directory. Run the following command : $ id=$(docker run -d -e LICENSE=accept -p 80:9080 -v /Users/sravan/Documents/tmp/libertyContainer_Hello.war:/opt/ibm/wlp/usr/servers/defaultServer/dropins/libertyContainer_Hello.war websphere-liberty) Note : /Users/sravan/Documents/tmp/libertyContainer_Hello.war : this was the local folder with my war file. Check if the server is started – $docker logs –tail=all -f $id You can now repeat step (5) short option and check the URL : http://XYZ:80/libertyContainer_Hello/ You should now see the content of your customised index.html from your web app! PS : Excellent Reference on this topic : David Currie’s Post on Liberty container announcement. https://developer.ibm.com/wasdev/blog/2014/12/04/liberty-docker/ […]

  10. […] following the WASdev site may have noticed that I’ve been doing some work with WebSphere Liberty and Docker recently. I was therefore pleased to have successfully made it off the wait list in time to travel […]

  11. Andre_Fernandes_BR December 08, 2014

    Silly question: should we consider this an “official” Liberty distro that will always be kept up to date?

    • David Currie December 09, 2014

      The image is brought to you by the WebSphere Application Server development team and it is certainly our intent to keep the 8.5.5 and latest tags up-to-date with fix packs as they become generally available (I have just updated the image to 8.5.5.4 to that end). It is probably worth re-iterating that this image is the ILAN licensed WebSphere Application Server for Developers and consequently its use in production is not supported.

Join The Discussion

Your email address will not be published. Required fields are marked *