Thursday, July 3, 2014

Nobody puts Baby in a Container

When it comes to Docker, using a Mac in a Linux world comes with some challenges.  There are a number of answers out there.  Which is best depends on how much you want to understand underneath the abstraction Docker provides.  In this blog entry we identify the problem and list a few solutions when it comes to network connectivity and Docker.

And when it comes to baby... we mean redis :)

It can be frustrating when the tooling abstracts you from the details,  yet you are required to understand the context of your environment to know that things are different.   This is the case when using Docker on platforms other than Linux.  In this blog we will simple put redis in a docker container and connect to it from the host OS.

Redis Docker Image on Ubuntu

Lets look at a working environment to establish expectations.  

It was only after working this for some time that I ran across a Redis Server.   Lesson 1:(again) search before you build your own thing :).  On my docker registry there is a kensipe/redis container image which contains redis-server.    You can pull the image with the following command.

sudo docker pull kensipe/redis


The container is start with the following command:

sudo docker run --name redis -p 6379:6379 -d kensipe/redis
# future invocations of the server could be 
sudo docker start redis

With redis installed on the host OS, a simple redis-cli connects to the docker instances of redis and away you go!   Isn't it wonderful?  Automatic port assignment and forwarding from localhost.

Once you go Mac...

The problem is on a Mac (and I assume any platform that needs to use boot2docker as a bridge),  the port forwarding is from the bridge, not from the host OS.  When you run docker run --name redis -p 6379:6379 -d kensipe/redis from the Mac command-line and the docker ps reveals that the port mapping is assigned to 0.0.0.0:6379. However starting up the redis-cli doesn't connect.

Fortunately the boot2docker command provides some help.   boot2docker ip will provide the IP address assigned to the underlying VM.  For me it results in 192.168.59.103.   Lets try redis-cli again.   

redis-cli -h 192.168.59.103

This results in a good connection to the redis server from the host OS.

VBox Network Mapping

If you still want to tie it to localhost, there are a couple of things you can do.  The more involved (not tested, but looks to be a superior way) is to follow the instructions http://ispyker.blogspot.com/2014/04/accessing-docker-container-private.html

Another approach is more simple IMO, but comes with some caveats.  We will inform Virtual Box (VBox) to map the ports for us.  The caveats are that you need to bring VBox down to configure it and when VBox comes up will take on that port (which could collide with local services).  Here is the solution:

VBoxManage modifyvm "boot2docker-vm" --natpf1 "redis,tcp,,6379,,6379"
boot2docker start

If you want to evaluate the configuration use:

VBoxManage showvminfo boot2docker-vm

If you want to delete that mapping to run redis locally, then

VBoxManage modifyvm boot2docker-vm --natpf1 delete tcp-port6379

With the mapping in place, the standard defaults for redis-cli launched from the host will map to the redis in a container.



Wednesday, February 20, 2013

Hunt the Wumpus


From the screen snapshot... what is wrong?

ok... it is using maven... what else?

ever seen a C: on a unix... good times!,  apparently the tests build this out.   Let's hope the day gets better than this :)

Tuesday, February 19, 2013

Java 6 End of Life

It may be important to note for companies running on Java, that Java 6 (probably the most common JVM platform for most of my enterprise customers) will reach it's EOL this month, Feb 2013.

Time to be moving to Java 7 if you haven't yet!

Thursday, February 7, 2013

New Year Commitments

Looking to recommit to this tech blog... so what to expect from 2013

Conferences

  1. looking forward to a new year with NFJS
  2. Poland YAY!  love Poland!
  3. JavaZone 2013 in Oslo
  4. UberConf 2013
that's what is scheduled currently

Blog Posts

I'm going try to post more frequently... and probably on themed subjects... are couple that come to mind:
  1. Lessons from clients:)  
  2. Tech Review or highlight of components / frameworks
If you have suggestions... please post.

Currently looking at writing a book on Spock as well... so we will see.

Technical Nugget

if you haven't noticed... take a look at asciidoc and asciidoctor.   All my tech writings and book will be written in asciidoc this year :)  In addition to all readme files on github, thanks to the githubbers and Dan Allen!
Sweet!!

Predictions for the year

Java 8 release YAY!
Mobile security will become an issue
Asciidoc takes over as the preferred markup

Sunday, September 2, 2012

JavaZone 2012

If you are looking for one of the top Java conferences, you need to take a look at JavaZone in Oslo, Norway.   Having been there a number of times over the last several years and comparing it to other Java conferences... It is top notch!   I'll be speaking there again in a couple of weeks and I'm certainly looking forward to it!

If you can sneak away... this is the one to come to!

Hope to see you there!

Monday, May 28, 2012

The Key Tenets - 7 Years after The Internet Services Disruption

October 28 2005 Ray Ozzie, having recently joined Microsoft (msft) at the time, put together an interesting manifesto with the subject title of "The Internet Services Disruption", with the purpose of "get all of us roughly on the same page".  For currently undisclosed reasons,  I had reason to review this document and found it completely fascinating.  Ray's foresight and ability to forecast the future is just amazing.   Although his writing was made public (good for us all), it was intended to inspire and position MSFT for it's next great phase.   Let's look at each of the key tenets Ray outlined and see who in our industry has the upper hand.

1.  The power of the advertising-supported model
Is MSFT winning here... definitely not.   Winners in this category are Google, making money off google.com.   Facebook making money on ads based again on high traffic visitations.  While these two companies are making good money with this concept, the company to watch is Apple.  Why?  Apple is actually empowering developers with this ad-support model through iAd.  Like ads or not... Apple is enabling developers to provide solutions free to consumers and are paid through ad hits.    There has also been a resent uptick in the number of ads off services like Hulu and youtube.   So there is no question that Ray nailed this tenet.

2. The effectiveness of a new delivery and adoption model
While Ray describes this in a try before you buy, and a readership and review model,  while being valid it is ubiquitous, so it is hard to give any one company brownie points for this.  Most of the good companies have their share of fan boys, VIP programs and evangelist (in the which MSFT does a stellar good at),   I would like to take this concept a little deeper.   New delivery... and delivery of what.  Considering operating systems and software, everyone is going disc-less.  Delivery of updates are internet provided.   But lets talk content... There is a new delivery mechanism for content... how do you watch your movies, how to you read your books, how do you get your music?   Where is MSFT in this space?  No where to be found.   Who owns this space?  Well... depending it seems divided between Amazon, NetFlix AND the big one?  Apple.   Apple hits gold stars in this category up and down their product like.  In fact one could say that the adoption of an iPod or iPad is a gateway into the full Apple stack.

3. The demand of compelling, integrated user experiences that "just work"
While I could go into detail and beat around the bush... this statement screams Apple.   While apple costs more in some cases, they are uncompromising and focus on the user experience.  They have all the advantages in this category as well.  they own the full tech stack... they don't have to make it work on a billion devices... they have theirs.

I consider myself a technologist and I don't "belong" to a specific tech group.  I see value in a number of camps.   The take away for me... is how insightful Ray was almost 7 years ago.  He nailed it.  It is too bad that MSFT doesn't seem to be paying attention to him. 

Thursday, April 5, 2012

Getting the Spock out of a Gradle War

I recent ran into a interesting situation, for which I thought it would be worth sharing. I have a new project with the following build needs: Java, Spring MVC and Spock Testing. The problem is simple... The WAR build in gradle was building a WAR file that included the Groovy libraries. This project has no need for groovy at runtime. Groovy is needed because I'm using Spock for my testing.

Gradle and providedCompile

In older versions of Gradle it was commonly necessary to manage the jars in the lib directory. In the maven world, there is a dependency scope of "provided". This scope basically means that the dependency will be provided on the server classpath, however for the purposes of compiling the code in the project it is necessary. From a WAR perspective it means use this dependency for compile, but do not include it in the lib directory of the WAR. Gradle within the last year has added the same feature as providedCompile or providedRuntime. In my project I have this very need with the servlet-api, shown below.
dependencies {
compile "org.springframework:spring-webmvc:$springVersion"
compile 'javax.servlet:jstl:1.2'
providedCompile 'javax.servlet:servlet-api:2.5'
}

Spock dependencies and Gradle

As Spock is a groovy testing tool, it is no surprise that Spock requires groovy. This requires a couple of well documented configurations in your gradle file. First, you'll have to add the groovy plugin. Second you have to set as a dependency the groovy version. But wait!!! The dependency for groovy doesn't have a scoping ability. This is area where the "model" of gradle breaks down a little bit IMO. Ideally you would be interested in expressing in the model that there are "testing" needs... and those testing needs require groovy and spock dependencies.
apply plugin: 'groovy'

def spockVersion = '0.5-groovy-1.8'
def springVersion = '3.1.0.RELEASE'

dependencies {
groovy 'org.codehaus.groovy:groovy-all:1.8.3'
testCompile 'junit:junit:4.8.1'
testCompile "org.spockframework:spock-core:$spockVersion"
testCompile "org.spockframework:spock-spring:$spockVersion"
}
With this groovy dependency any build of WAR will result in a the groovy-all-?.?.?.jar file being added to the the WEB-INF/lib directory. The problem is I have no current interest in having groovy in production for this project. What to do? What to do?

Gradle Doc to the Rescue

I find that a large number of people (usually new to gradle) struggle with discovering how to resolve such a problem. The best starting point for getting to know gradle is the gradle user guide documentation, but the best starting point to use as a reference is the gradle dsl documentation (http://gradle.org/docs/current/dsl). Hopefully it is obvious that what we want to change is the build of the WAR. So lets look at the War task. Here we see all of it's properties... which includes the classpath property. The documentation for this property clearly states that this property affects the WEB-INF/classes and the WEB-INF/lib. Diving deeper into that property we see the default behavior which is:
project.configurations.runtime - project.configurations.providedRuntime
So our logical solution would be to include a war task configuration for the building of the classpath like this:
war {
classpath = classpath - project.configurations.groovy
}


Happy Coding! and may your builds never fail!