This project puts Consul in scratch docker container. It is available on Docker Hub and can be pulled using the following command.
docker pull alectolytic/consul
You will note that this is a tiny image.
$ docker images | grep docker.io/alectolytic/consul
docker.io/alectolytic/consul latest abf9a1e6fbd2 3 minutes ago 15.33 MB
By default, a single consul agent is run in server mode.
docker run --rm -it alectolytic/consul
This is equivalent to executing the following.
consul agent -server -bootstrap \
-config-dir=/etc/consul -data-dir=/var/lib/consul \
-client=0.0.0.0 -ui-dir=/usr/share/consul-ui
The output looks similar to this.
==> WARNING: Bootstrap mode enabled! Do not enable unless necessary
==> WARNING: It is highly recommended to set GOMAXPROCS higher than 1
==> Starting raft data migration...
==> Starting Consul agent...
==> Starting Consul agent RPC...
==> Consul agent running!
Node name: '52b7a6700f2c'
Datacenter: 'dc1'
Server: true (bootstrap: true)
Client Addr: 0.0.0.0 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)
Cluster Addr: 172.17.0.63 (LAN: 8301, WAN: 8302)
Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false
Atlas: <disabled>
==> Log data will now stream in as it occurs:
2015/08/11 22:11:06 [INFO] serf: EventMemberJoin: 52b7a6700f2c 172.17.0.63
2015/08/11 22:11:06 [INFO] serf: EventMemberJoin: 52b7a6700f2c.dc1 172.17.0.63
2015/08/11 22:11:06 [INFO] raft: Node at 172.17.0.63:8300 [Follower] entering Follower state
2015/08/11 22:11:06 [INFO] consul: adding server 52b7a6700f2c (Addr: 172.17.0.63:8300) (DC: dc1)
2015/08/11 22:11:06 [INFO] consul: adding server 52b7a6700f2c.dc1 (Addr: 172.17.0.63:8300) (DC: dc1)
2015/08/11 22:11:06 [ERR] agent: failed to sync remote state: No cluster leader
2015/08/11 22:11:08 [WARN] raft: Heartbeat timeout reached, starting election
2015/08/11 22:11:08 [INFO] raft: Node at 172.17.0.63:8300 [Candidate] entering Candidate state
2015/08/11 22:11:08 [INFO] raft: Election won. Tally: 1
2015/08/11 22:11:08 [INFO] raft: Node at 172.17.0.63:8300 [Leader] entering Leader state
2015/08/11 22:11:08 [INFO] consul: cluster leadership acquired
2015/08/11 22:11:08 [INFO] consul: New leader elected: 52b7a6700f2c
2015/08/11 22:11:08 [INFO] raft: Disabling EnableSingleNode (bootstrap)
2015/08/11 22:11:08 [INFO] consul: member '52b7a6700f2c' joined, marking health alive
2015/08/11 22:11:10 [INFO] agent: Synced service 'consul'
# create data container
docker create --entrypoint=_ -v /var/lib/consul --name consul-data scratch
# run consul
docker run --rm -it --volumes-from alectolytic/consul
docker run --rm -it alectolytic/consul agent -server -bootstrap -data-dir /var/lib/consul
docker run --rm -it -v /path/to/config.json:/etc/consul/config.json alectolytic/consul agent -config-file=/etc/consul/config.json
NOTE: If running on an SELinux enabled system, run chcon -Rt svirt_sandbox_file_t /path/to/config.json
before staring consul.
EXPOSE \
53/tcp 53/udp \
8300/tcp \
8301/tcp 8301/udp \
8302/tcp 8302/udp \
8400/tcp \
8500/tcp \
8600/tcp 8600/udp