Monthly Archives: December 2015

JBoss EAP 7 and NoSQL using Java EE and Docker

JBoss EAP 7 Beta is now released, many congratulations to Red Hat and particularly to the WildFly team!

There are plenty of improvements coming in this release as documented in Release Notes. One of the major themes is Java EE 7 compliance.

JBoss EAP 7 and Java EE 7

IBM and Oracle already provide commercially supported Java EE 7-compliant Application Servers. And now Red Hat will be joining this party soon as well. Although WildFly has supported Java EE 7 for 2+ years but commercial support is a critical for open source to be adopted enterprise-wide. So this is good news!

You can learn all about different Java EE 7 APIs in the DZone Refcardz that I authored along with @alrubinger.

Java EE 7 Refcardz

There are plenty of “hello world” Java EE 7 Samples that should all run with JBoss EAP. Hopefully somebody will update the pom.xml and add a new profile.

Why NoSQL?

If you are building a traditional enterprise application then you might be fine using an RDBMS. There are plenty of advantages of using RDBMS but using a NoSQL database instead has a few advantages:

  • No need to have a pre-defined schema and that makes them a schema-less database. Addition of new properties to existing objects is easy and does not require ALTER TABLE. The unstructured data gives flexibility to change the format of data any time without downtime or reduced service levels. Also there are no joins happening on the server because there is no structure and thus no relation between them.
  • Scalability, agility and performance is more important than the entire set of functionality typically provided by an RDBMS. This set of databases provide eventual consistency and/or transactions restricted to single items but more focus on CRUD.
  • NoSQL are designed to scale-out (horizontal) instead of scale-up (vertical). This is important knowing that databases, and everything else as well, is moving into the cloud. RBDMS can scale-out using sharding but requires complex management and not for the faint of heart. Queries requiring JOINs across shards is extremely inefficient.
  • RDBMS have impedance mismatch between the database structure and the domain classes. An Object Relational Mapping, such as one provided by Java Persistence API or Hibernate is needed in such case.
  • NoSQL databases are designed for less management and simpler data models lead to lower administration cost as well.

So you are all excited about NoSQL now and want to learn more:

  • Why NoSQL?
  • Why do successful enterprises rely on NoSQL?
  • Top 10 Enterprise NoSQL Usecases

In short, there are four different types of NoSQL databases:

  • Document: Couchbase, Mongo, and others
  • Key/Value: Couchbase, Redis, and others
  • Graph: Neo4J, OrientDB, and others
  • Column: Cassandra and others

Java EE 7 provides Java Persistence API that does not provide any support for NoSQL. So how do you get started with NoSQL with JBoss EAP 7?

This blog will show how to query a Couchbase database using simple Java EE application deployed on JBoss EAP 7 Beta.

What is Couchbase?

Couchbase is an open-source, NoSQL, document database. It allows to access, index, and query JSON documents while taking advantage of integrated distributed caching for high performance data access.

Developers can write applications to Couchbase using different languages (Java, Go, .NET, Node, PHP, Python, C) multiple SDKs. This blog will show how you can easily create a CRUD application using Java SDK for Couchbase.

Run JBoss EAP 7

There are two ways to start JBoss EAP 7.

Download and Run

  • Download JBoss EAP 7 Beta and unzip.
  • Start the application server as:

Docker Run

In a containerized world, you just docker run to run your JBoss EAP. However, JBoss EAP image does not exist on Docker Hub and so the image needs to be explicitly built. You still need to explicitly download JBoss EAP and then use the following Dockerfile to build the image:

The image is built as:

And then you can run the JBoss EAP 7 container as:

Notice, how application and management ports are bound to all network interfaces. This will simplify to deploy the application to this JBoss EAP instance later.

Stop the server as we will show an easier way to start it later.

Start Application Server and Database

The Java EE application will provide a HTTP CRUD interface over JSON documents stored in Couchbase. The application itself will be deployed on JBoss EAP 7 Beta. So it would require to start Couchbase and JBoss EAP.

Use the Docker Compose file from to start Couchbase and JBoss EAP 7 container:

The application is started as:

The started containers can be seen as:

Configure Couchbase Server

Clone couchbase-javaee application. This Java EE application uses Couchbase Java SDK APIs to connect to the Couchbase server. The bootstrap code is:

and is invoked from Database abstraction.

Couchbase Server can be configured using REST API. These REST APIs are defined in a Maven profile in pom.xml of this application. And so configure Couchbase server as:

Deploy Java EE Application to JBoss

Java EE Application can be easily deployed to JBoss EAP 7 Beta using the WildFly Maven Plugin. This is also defined as a Maven profile in pom.xml as well.

Deploy the application as:

Access the Application

As mentioned earlier, the application provides HTTP CRUD API over JSON documents stored in Couchbase.

Access the application as:

CRUD operations (GET, POST, PUT, DELETE) can be performed on Airline resource in the application. Complete CRUD API is documented at

This blog explained how to access a NoSQL database from JBoss EAP 7.

Read more about Couchbase 4:

  • What’s New in Couchbase Server 4.1
  • Couchbase Server documentation
  • Talk to us on Couchbase Forums
  • Follow @couchbasedev or @couchbase

Learn more about Couchbase in this recent developer-focused webinar:

Couchbase on OpenShift 3

OpenShift is Red Hat’s open source PaaS platform. OpenShift 3 provides a holistic experience of running your applications using Docker and Kubernetes. In a classic Red Hat way, all the work is done in the open source at OpenShift Origin. This also drives the next major release of OpenShift Online and OpenShift Enterprise.

OpenShift 3 using Docker and Kubernetes for container orchestration makes it really simple to bring any products that have a Docker image to run with minimal effort. This blog explains how to get started with Couchbase on OpenShift 3.

OpenShift-logoCouchbase Logo

Getting Started with OpenShift 3

  • Download the latest Vagrant box (1.1 as of this writing) and Vagrantfile from: Copy them in the same directory.Vagrantfile is configured for 2GB memory and can be updated if you need to run more containers. OpenShift Master, Node, Docker Registry, and other components run inside the VM.This blog was written using Vagrant 1.7.4 and VirtualBox 5.0.10r104061.
  • Add the Vagrant Box:
  • Start the Virtual Machine:

Download and Configure OpenShift 3 Client

  • Download Mac 64-bit client tools (gem install rhc is for v2 only) from and extract them a in directory. The listing looks like:
  • Verify the client version:
  • Remove ~/.kube/configor rename to something else.
  • Login to OpenShift:

Create Couchbase Application in OpenShift 3

  • Create a new Couchbase instance:
    arungupta/couchbase is used as it uses Couchbase REST API to preconfigure the Couchbase server with:

    • Memory and index quota
    • Query, Data, and Index service
    • Username and password credentials
    • Install travel-sample bucket

    This sample bucket will be used later for querying data.

  • Check the status of deployment:

  • Find the list of Pods:

  • Get more details about the Couchbase pod:

Query Couchbase Sample Bucket

  • Log into the Vagrant box:

  • Find a list of all the running containers:

    Search for Couchbase container:

    Get the id for our container:

  • Get IP address of the Pod where Couchbase server is running:

  • Use the IP address shown above to start Couchbase Query CLI:

  • Query the sample bucket:


This blog shows the very basics of getting started with Couchbase on OpenShift 3. Future blogs will show:

  • How to deploy an application to OpenShift and use this Couchbase
  • How to make this application accessible outside OpenShift
  • How to scale Couchbase in OpenShift
  • Possibly some other interesting items that come along

Do you have a suggestion on what you’d like to see?

Read more about Couchbase 4.1:

  • What’s New in Couchbase Server 4.1
  • Download Couchbase Server 4.1
  • Couchbase Server documentation
  • Talk to us on Couchbase Forums
  • Follow @couchbasedev or @couchbase

Couchbase 4.1 Docker Container

Couchbase Logo

Couchbase 4.1 was recently released. Highlights of this release are:

  • N1QL: Complete SQL CRUD Support with N1QL for Batch and OLTP Applications
  • Covering Indexes
  • Prepared Statements
  • Additional Supported Platforms

You can read all about it at Introducing Couchbase Server 4.1 and also watch a replay of Hands-on Introduction to What’s New in Couchbase 4.1:

Getting Started with Couchbase 4.1 and Docker

Use the following Docker Compose file:

to start a pre-configured Couchbase 4.1 Docker container:

This will:

  • Start Couchbase 4.1 Server (Dockerfile)
  • Configure it using Couchbase REST API as explained in Configure Couchbase Docker Container using REST API
    • Sets up memory and index quota
    • Sets up Query, Data, and Index service
    • Configures username and password credentials
    • Install travel-sample bucket

The logs can be seen as:

Connect to CBQ (Couchbase Query tool):

Learn more about Running N1QL Queries from Command Line.

Stop the server:

Remove the container:

Read more about Couchbase 4.1:

  • What’s New in Couchbase Server 4.1 documentation
  • Download Couchbase Server 4.1
  • Couchbase Server documentation
  • Release Notes for 4.1
  • Couchbase ODBC and JDBC Drivers with SQL Connector

Share feedback with us at or Stackoverflow.


Docker Bridge and Overlay Network with Compose Variable Substitution

Docker Multi-Host networking allows you to create virtual networks and attach containers to them so you can create the network topology that is right for your application. Bridge networks can be created for single host and overlay networks can be created for multiple hosts. Creating application-specific networks provides complete isolation for containers.

Docker Compose file can be targeted at a single host, and --x-networking will create a bridge network exclusive for the application. If the sample application is targeted at multiple hosts, say using Docker Swarm cluster, then an overlay network is created. Single host networking and multi host networking provide more details on how to set this up.

What if a bridge or an overlay network already exists and you’d like to assign this to your application started using Docker Compose?

Docker Networking

Docker 1.9 introduced variable substitution, and we can use that feature to target an application to a pre-created network.

Create New Docker Bridge Network

  1. Create a new network:
  2. List the networks:
    Docker create three networks for each host automatically:

    bridge Default network that containers connect to. This is docker0 network in all Docker installations.
    none Container-specific networking stack
    host Adds a container on hosts networking stack. Network configuration is identical to the host.

    In addition, you also see mynet network that was just created.

  3. Inspect the newly created network using docker network inspect mynet:

    No containers are assigned to it yet.

Docker Compose and Networking

  1. This new network can be used for any new container using docker run --net=<NETWORK> command. This blog will show how to target this network to a Compose file:

    Note how net is specified here to use a custom network. This Compose file is at:

  2. Start the application, using our newly created network, as:

  3. Inspect the network again:

    And now the two containers are assigned to this network as well.

  4. Check the container id using docker ps:

  5. Check the network for one container:

  6. More details about the network:

  7. More details about the container can be found using docker inspect, relevant portion is shown here:

Create New Docker Overlay Network

Creating a new Docker overlay network requires to setup a key/value service and a Docker Swarm cluster. Multi-host and multi-container blog provide more details on that.

More details at Docker Networks.

Show Layers of Docker Image

Every speaking opportunity is a learning lesson, and hence a new opportunity to share. This blog will address one of the questions that has been bothering me for the past few days. It is about how to show different layers of Docker image, and their sizes, after it is downloaded.

Docker Logo

I was invited to talk about Docker for Java developers at Peru JUG this morning. The recording is now available:

The real content starts from 5:27.

Lets address the question now.

Each Docker image consists of a series of layers. Here is a quote from

Each image consists of a series of layers. Docker makes use of union file systems to combine these layers into a single image. Union file systems allow files and directories of separate file systems, known as branches, to be transparently overlaid, forming a single coherent file system.

How does a Docker image work?

The exact size of the image can be easily seen using docker images:

The command to show different layers, and their size, is docker history:

This command shows different layers, command used for each layer, and the exact size of each image.

The corresponding Dockerfile for this image is at

Now I can compare the Dockerfile with the exact size and easily find which image layers are the biggest. For example, biggest contributors in this Couchbase image are shown below:

  • Ubuntu from Dockerfile 12.04 is 135.9 MB
  • apt-get from Dockerfile causes another 23.57 MB
  • Couchbase server is 212 MB

--no-trunc can be specified as an additional CLI option to history to show the complete command executed to build the layer.

As always, the latest slides are available at

“Network timed out” Docker error

One of the most dreaded errors seen during Docker workshops around the world is:

Restarting Docker Machine is typically known to fix the issue.

Lets say your machine name is couchbase-javaee. Machine can be restarted as:

Setting up Docker environment may work:

But certain times it gives the error:

So you need to regenerate the certificates. A successful execution will give output as:

And sometimes even this command goes berserk and gives the output:

Either way, setting Docker environment:

sets up the environment correctly.

Docker Machine, Swarm and Compose for multi-container and multi-host applications with Couchbase and WildFly

This blog will explain how to create multi-container application deployed on multiple hosts using Docker. This will be achieved using Docker Machine, Swarm and Compose.

Yes, all three tools together makes this blog that much more interesting!

Docker Swarm Machine Compose

The diagram explains the key components:

  • Docker Machine is used to provision multiple Docker hosts
  • Docker Swarm will be used to create a multi-host cluster
  • Each node in Docker Swarm cluster is registered/discovered using Consul
  • Multi-container application will be deployed using Docker Compose
  • WildFly and Couchbase are provisioned on different hosts
  • Docker multi-host networking is used for WildFly and Couchbase to communicate

In addition, Maven is used to configure Couchbase and deploy application to WildFly.

Latest instructions at Docker for Java Developers.

No story, just pure code, lets do it!

Create Discovery Service using Docker Machine

  1. Create a Machine that will host discovery service:
  2. Connect to this Machine:
  3. Run Consul service using the following Compose file:
    This Compose file is available at
    Started container can be verified as:

Create Docker Swarm Cluster using Docker Machine

Swarm is fully integrated with Machine, and so is the easiest way to get started.

  1. Create a Swarm Master and point to the Consul discovery service:
    Few options to look here:

    1. --swarm configures the Machine with Swarm
    2. --swarm-master configures the created Machine to be Swarm master
    3. --swarm-discovery defines address of the discovery service
    4. --cluster-advertise advertise the machine on the network
    5. --cluster-store designate a distributed k/v storage backend for the cluster
    6. --virtualbox-disk-size sets the disk size for the created Machine to 5GB. This is required so that WildFly and Couchbase image can be downloaded on any of the nodes.
  2. Find some information about this machine:
    Note that the disk size is 5GB.
  3. Connect to the master by using the command:
  4. Find some information about the cluster:
  5. Create a new Machine to join this cluster: