libswarm demo – logging

At Dockercon, we announced a new project being worked on called “libswarm”. I wanted to clarify what exactly libswarm is, what it does, and what it doesn’t do.

First, libswarm is not itself an orchestration tool. It does not and will not replace any orchestration tools.

Libswarm is a library first and foremost and not an end-user tool. It is a library that helps make it relatively trivial to compose other disparate tools together, including but not limited to orchestration tools.

Just a quick demo showing off what libswarm can do with logging. I will be using code from this gist: https://gist.github.com/cpuguy83/b7c0f42e903bc13c46d6

Demo time!

# start a container that prints to stdout
docker -H tcp://10.0.0.2:2375 run -d --entrypoint /bin/sh debian:jessie -c \
    'while true; do echo this is a log message; sleep 1; done'

# fire up swarmd
./swarmd 'logforwarder tcp://10.0.0.2:2375' stdoutlogger
Getting logs tcp://10.0.0.2:2375 [agitated_yonath]
2014-07-17 19:04:22.42915222 +0000 UTC	tcp://10.0.0.2:2375	agitated_yonath	INFO	this is a log message

2014-07-17 19:04:23.43114032 +0000 UTC	tcp://10.0.0.2:2375	agitated_yonath	INFO	this is a log message

So we told swarmd to fire up the logforwarder backend and connect to the docker daemon on tcp://10.0.0.2:2375, attach to each of the containers in the daemon, convert the stdout/stderr streams to log messages and forward them into the stdoutlogger (which is a backend made simply for demo purposes) which prints to the terminal’s stdout.

# Now lets connect to multiple daemons with multiple containers
docker -H tcp://10.0.0.2:2375 run -d --entrypoint /bin/sh debian:jessie -c \
    'while true; do echo this is a log message; sleep 1; done'
docker -H tcp://10.0.0.2:2375 run -d --entrypoint /bin/sh debian:jessie -c \
    'while true; do echo this is a log message; sleep 1; done'

docker -H tcp://10.0.0.3:2375 run -d --entrypoint /bin/sh debian:jessie -c \
    'while true; do echo this is also a log message; sleep 1; done'


./swarmd 'logforwarder tcp://10.0.0.2:2375 tcp://10.0.0.3:2375' stdoutlogger
Getting logs tcp://10.0.0.2:2375 [agitated_yonath romantic_wozniak]
Getting logs tcp://10.0.0.3:2375 [hopeful_babbage]
2014-07-17 19:40:22.93898444 +0000 UTC	tcp://10.0.0.2:2375	agitated_yonath	INFO	this is a log message

2014-07-17 19:40:23.26841138 +0000 UTC	tcp://10.0.0.3:2375	hopeful_babbage	INFO	this is also a log message

2014-07-17 19:40:23.63765218 +0000 UTC	tcp://10.0.0.2:2375	romantic_wozniak	INFO	this too is a log message

2014-07-17 19:40:23.94244022 +0000 UTC	tcp://10.0.0.2:2375	agitated_yonath	INFO	this is a log message

2014-07-17 19:40:24.27086067 +0000 UTC	tcp://10.0.0.3:2375	hopeful_babbage	INFO	this is also a log message

2014-07-17 19:40:24.64303259 +0000 UTC	tcp://10.0.0.2:2375	romantic_wozniak	INFO	this too is a log message

Here we have the logforwarder connecting to 2 docker backends, attaching to each of the containers and forwarding the stdout/stderr streams to the stdoutlogger.

Instead of stdoutlogger, this could be swapped out for syslog, logstash, whatever… it just needs to implement the libswarm “Log” verb.

Libswarm in Docker

I see various pieces of Docker core being broken into smaller libswarm services that come together to make Docker.
I see tools that hook into this libswarm API to extend native Docker functionality. No more bind-mounting Docker sockets into containers (which, btw, is super dangerous).

Libswarm is the API you will use in order to in order to interact with Docker, and not the traditional REST API (though this will probably be available in one form or another).

Want to talk more about libswarm? Join us on IRC @ #libswarm on freenode or at our github repo: github.com/docker/libswarm

Leave a Reply