An open API service indexing awesome lists of open source software.

https://github.com/eyalgolan/consulondockerdemo

A project I've made a few years back - Consul running inside docker containers
https://github.com/eyalgolan/consulondockerdemo

Last synced: 5 months ago
JSON representation

A project I've made a few years back - Consul running inside docker containers

Awesome Lists containing this project

README

          

# ConsulOnDockerDemo
A project I've made a few years back - Consul on docker containers.

Note that this project was built in 2015, and both Docker and Consul made significant changes and upgrades since then.

# Setup

1. Start leader
```
docker run -d -p 8400:8400 -p 8500:8500 -p 8600:53/udp -h node1 progrium/consul -server -bootstrap -ui-dir /ui
```

2. Get node1's ip (```docker ps``` -> copy the node1's id -> ```docker inspect id | grep 172```)

3. Change the ip in httpd_consul's script file, ```client1.json``` to node1's ip

4. Rebuild ```httpd_consul``` image
```
docker build -t httpd_consul . (from the httpd_consul folder)
```

5. Start the Consul containers
```
docker run -p 80:80 -p 8401:8400 -p 8501:8500 -p 8601:53/udp -h node2 httpd_consul
```

key location: /data/tmp/state/data.mdb

# Events
The servers update each other in the following way:

The script that runs on the container with the application and consul:
```
#!/bin/bash
./root/script-httpd & \
./root/consul agent -data-dir"/tmp/consul" -config-file=/root/client1.json /root/watch1.json & \
./root/consul watch -http-addr=172.17.4.181:8500 -type=key -key "test/index.html" "/usr/bin/my-key-handler.sh"
```
The watcher:
```
"watches": [
{
"type": "keyprefix",
"key: "test/index.html",
"handler": "/usr/bin/my-key-handler.sh"
}
]
```
The script the watcher runs if an event is identified:
```
#!/bin/bash
echo "New event: ${SERF_EVENT}. Data follows..."

while read line; do
{
printf "${line}\n"
printf "${line}\n" >>/var/www/html/eventlog.txt
}

curl http://172.17.4.181:8500/v1/kv/test/index.html?raw > /var/www/html/index.html
done
```