Getting started with Docker and WildFly

This is the first of a set of tutorials about the Docker framework. In this one we will learn how to install the Docker platform on a Linux Centos machine and pull and execute a WildFly image on the top of it.

First of all, what is Docker ? Docker is a container-based software framework for automating deployment of applications. “Containers” are encapsulated, lightweight, and portable application modules. The major (intended) benefit of using a container is that your application will run consistently on and between any server, be it cloud or dedicated, or of varying operating systems.

Centos 6 or 7 ?

The Docker package is provided by default as part of CentOS-7. If you are running the CentOS 6.5 like me, you have to install the EPEL repository. You can find all details concerning the EPEL installation here: https://fedoraproject.org/wiki/EPEL#How_can_I_use_these_extra_packages.3F

In my case I've installed the EPEL repository as follows:

rpm -iUvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

Then, as a matter of best practice, we’ll update our packages:

yum update -y

Installing Docker

Done with EPEL, let’s install Docker by installing the docker-io package:

yum -y install docker-io

Once Docker is installed, you will need to start the docker daemon.

[jboss@localhost ~] $ sudo service docker start

Starting cgconfig service:                                 [  OK  ]

Starting docker:                                       [  OK  ]

Great! now your Docker is ready to rock!

Pulling Docker images

As next step, we will start pulling Docker images. We will demonstrate how to install and run a wildfly vanilla Docker image. In order to do that issue the following command:

[jboss@localhost ~]$ sudo docker pull jboss/wildfly

Once completed downloading the image, we will verify the available images in our Docker platform:

[jboss@localhost ~]$ sudo docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

centos              centos5             192178b11d36        6 days ago          466.9 MB

centos              centos6             70441cac1ed5        6 days ago          215.8 MB

centos              centos7             ae0c2d0bdc10        6 days ago          224 MB

centos              latest              ae0c2d0bdc10        6 days ago          224 MB

jboss/wildfly       latest              365390553f92        2 weeks ago         948.7 MB

In order to start the wildfly application server, simply issue:

[jboss@localhost ~]$ sudo docker run -it jboss/wildfly 
=========================================================================

  JBoss Bootstrap Environment

  JBOSS_HOME: /opt/jboss/wildfly

  JAVA: /usr/lib/jvm/java/bin/java

  JAVA_OPTS:  -server -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true

=========================================================================

. . . .

15:05:08,748 INFO  [org.jboss.ws.common.management] (MSC service thread 1-2) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.2.4.Final

15:05:08,899 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management

15:05:08,899 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990

15:05:08,900 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.1.0.Final "Kenny" started in 9780ms - Started 184 of 233 services (81 services are lazy, passive or on-demand)

Seems the server started correclty. We can check it by issuing the docker ps command which retrieves the images process which are running and the ports engaged by the process:

[jboss@localhost ~]$ sudo docker ps

CONTAINER ID        IMAGE                  COMMAND                CREATED             STATUS              PORTS                NAMES

cac63ed21d67        jboss/wildfly:latest   "/opt/jboss/wildfly/   3 minutes ago       Up 3 minutes        8080/tcp, 9990/tcp   happy_newton    

If you have notices the startup log of the server, you should have discovered that the server is located in the /opt/jboss/wildfly and that by default the public interfaces are bound to the 0.0.0.0 address whilst the admin interfaces are bound just to localhost. This information will be useful to learn how to customize the server.

So, in order to access to our wildfly server, we need to know which address has been chosen by the application server for socket binding. We will use the docker inspect command passing as parameter the ID of the Container we have already found (cac63ed21d67):

[jboss@localhost ~]$ sudo docker inspect -f '{{ .NetworkSettings.IPAddress }}' cac63ed21d67

The above command will output:

172.17.0.11

So the server is available at the 172.17.0.11 IP Address. Now let's open the console at that address: http://172.17.0.11:8080

docker tutorial wildfly

Et volià! WildFly served on a Docker image.

In the next part of this series of Docker tutorials we will learn how to customize the Docker image installation and deploy some applications on the top of it.

Stay Tuned!

References: 

http://blog.arungupta.me/2014/07/getting-started-with-docker/

https://docs.docker.com/installation/centos/

Follow us on Twitter