Fun with Flocker

13Aug14

Before writing my InfoQ story about Flocker I ran through my now usual process of getting my 3 tier demo[1] working on it (in addition to running through the getting started guide[2]).

What I found is that Flocker doesn’t yet support multi container apps, but then it is only at release 0.1 (and proper multi container support if promised for 0.2). It was however possible to get things working with a little hacking.

Database

Flocker is made for running stateful apps, so getting MySQL working was pretty straightforward. I created the following files:

"version": 1
"nodes":
  "172.16.255.250": ["mysql-volume-example"]
  "172.16.255.251": []
"version": 1
"applications":
  "mysql-volume-example":
    "image": "cpswan/todomvc.mysql"
    "ports":
    - "internal": 3306
      "external": 3306
    "volume":
      # The location within the container where the data
      # volume will be mounted:
      "mountpoint": "/var/lib/mysql"

To get it fired up I then ran:

$ flocker-deploy mysql-deployment.yml mysql-application.yml

After something of a wait for my container image to be pulled from Docker Hub I had a running database that I could connect to with the mysql client. I then created an alternative deployment file and moved the database to another host:

"version": 1
"nodes":
  "172.16.255.250": []
  "172.16.255.251": ["mysql-volume-example"]
$ flocker-deploy mysql-deployment-moved.yml mysql-application.yml

Some further testing confirmed that the database was working. I could even connect to the other VM and use the Flocker proxy to get through to my container.

App and Web Servers

I used ssh to connect to the Flocker VM running the database and attached the app and web servers in the usual way:

$ docker run -dp 4567:4567 --name todomvc_app \
--link mysql-volume-example:db cpswan/todomvc.sinatra
$ docker run -dp 443:443 --name todomvc_ssl \
--link todomvc_app:app cpswan/todomvc.ssl

A quick test with a web browser attached through and SSH port forward confirmed that everything was working.

I then had a go at moving the database again, which got me a screen full of SQL errors. The app server could no longer connect to the container it had linked to, and the Flocker proxy wasn’t helping.

Hacking the link

The app server is configured using environment variables that are populated by the Docker linking mechanism, so DB_PORT_3306_TCP_ADDR gets set to something like 172.17.0.9:3306. Using a slightly different command line this can be set to use the local Flocker proxy rather than connecting directly to a container that might not stay there (after stopping and removing the todomvc_app container):

$ docker run -dp 4567:4567 --name todomvc_app \
-e "DB_PORT_3306_TCP_ADDR=172.16.255.250:3306" \
cpswan/todomvc.sinatra

With that done the app server was able to connect to the MySQL database, whichever VM it was running on.

Notes

[1] I’ve also put the demo onto Fig and Panamax.
[2] Luckily I already had a Linux machine with VirtualBox and Vagrant all set up after playing with Panamax over the weekend.



No Responses Yet to “Fun with Flocker”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: