Tuesday, 30 August 2016

Docker and Liberty - Scripting it

Next, I wanted to create a mechanism to allow me to automate the use of WebSphere Liberty Profile on Docker, with a view to creating a little process to: -

(1) Create a Docker container from an existing WLP image
(2) Deploy a simple web application ( I'm using Ferret, which is akin to good old Snoop from here )
(3) Monitor the WLP logs
(4) Run a basic functional test
(5) Stop the container once testing has completed
(6) Remove the container

so this is with what I came up: -

Start a Container and assign Container ID to a variable - foobar

foobar=`docker run -d -t -p 80:9080 -p 443:9443 websphere-liberty:latest`

Copy a WAR file to the Liberty dropins folder

docker cp ~/Downloads/ferret.war $foobar:/opt/ibm/wlp/usr/servers/defaultServer/dropins

Functional-test the Ferret app - via a browser


Watch the Liberty logs - found in /logs/messages.log

docker logs $foobar -f

[AUDIT   ] CWWKF0011I: The server defaultServer is ready to run a smarter planet.
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://878db1a296e5:9080/ferret/
[AUDIT   ] CWWKZ0001I: Application ferret started in 0.735 seconds.

Start an interactive command-line to the container

docker exec -i -t $foobar /bin/bash

Stop the Liberty runtime

docker exec -i -t $foobar bash -c "/opt/ibm/wlp/bin/server stop"

Watch the Liberty logs - found in /logs/messages.log

docker logs $foobar -f

[AUDIT   ] CWWKE0055I: Server shutdown requested on Tuesday, August 30, 2016 at 12:22 PM. The server defaultServer is shutting down.
[AUDIT   ] CWWKT0017I: Web application removed (default_host): http://878db1a296e5:9080/ferret/
[AUDIT   ] CWWKZ0009I: The application ferret has stopped successfully.
[AUDIT   ] CWWKI0002I: The CORBA name server is no longer available at corbaloc:iiop:localhost:2809/NameService.
[AUDIT   ] CWWKE0036I: The server defaultServer stopped after 45.191 seconds.

Remove the Container

docker rm $foobar

Which is nice :-)

No comments: