Creating a docker container
===========================
make docker

Running the container
=====================
docker run --name keepalived --cap-add=NET_ADMIN --net=host -d keepalived

To use an alternative configuration file
----------------------------------------
With a configuration file on the host at /data/keepalived.conf (with extra command line options):

docker run --cap-add=NET_ADMIN --net=host -v /data/keepalived.conf:/etc/keepalived/keepalived.conf keepalived --log-detail --dump-conf
(the --security-opt label=disable option may need to be added to the command line)

Useful docker commands are:
===========================
docker logs keepalived 2>&1 | less	# view system logs of container
docker exec -it keepalived /bin/sh	# execute shell in container
docker exec keepalived kill -TERM $(docker exec keepalived cat /var/run/keepalived.pid)		# To shutdown keepalived
docker rm -f keepalived			# Remove the container

keepalived is unable to load the ip_tables, ip6_tables, xt_set and ip_vs
modules from within the container, so ensure they are already loaded in
the host system.

It is important that keepalived is shutdown before the container is removed,
otherwise iptables, ipsets and ipvs configuration can be left over in the
host after the container terminates.

Debugging
=========
To generate a core file in the container, if
/proc/sys/kernel/core_pattern needs to be updated it needs to be done in
the host system, and not from the container (or in other words the
-M option to keepalived does not work within a container).
Installing gdb in the container (edit the Dockerfile to add it before
make build) may be helpful if you need to examine core files in the container.
The -m option will need to be added to the keepalived command line.

Alternative building of docker container
=======================================
There is a very useful github project that was maintained by osixia
for building a docker container with keepalived.

To use, run the following:
git clone https://github.com/osixia/docker-keepalived.git
cd docker-keepalived
make build
docker run --name keepalived --cap-add=NET_ADMIN --net=host \
  --env KEEPALIVED_INTERFACE=eth0 -d osixia/keepalived:2.2.4 \
	# or whatever version of keepalived you have

To update the keepalived source code, put a new tarball in the image
directory named keepalived-${KEEPALIVED_VERSION}.tar.gz (the Dockerfile
may need updating with a new version). Now edit image/Dockerfile to
remove the 'curl' line and add
COPY keepalived-${KEEPALIVED_VERSION}.tar.gz keepalived.tar.gz
before the RUN line.

To change the command line options that keepalived is run with,
edit image/service/keepalived/process.sh

https://github.com/acassen/keepalived/issues/758 has another example
of building a docker image.
