-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathdocker-compose.yml
309 lines (290 loc) · 8.78 KB
/
docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
volumes:
consul-leader:
consul-worker-1:
consul-worker-2:
etc-pihole:
etc-pihole-dnsmasq:
vault-file:
vault-logs:
dnsmasq-1:
dnsmasq-2:
#define internal docker networks for container connectivity
networks:
internal:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.16.238.0/24
#define docker containers as services
services:
# ad-blocking DNS service
pihole:
image: pihole/pihole:latest
entrypoint: ''
deploy:
replicas: 1
restart_policy:
condition: any
command:
- /bin/bash
- -xc
- |
IP="$$(awk '/32 host/ && f ~ /172.16.238/ { print f; exit }; {f=$$2}' /proc/net/fib_trie)"
until curl -sSfIo /dev/null http://consul:8500/ui/; do sleep 1;done
consul-agent.sh \
--consul-host consul \
--advertise "$$IP" \
--service '{"checks": [{"id": "http", "name": "PiHole IU available on port 80", "http": "http://0.0.0.0/admin/login.php", "interval": "10s", "status": "passing" }], "service": {"name": "pihole", "tags": ["portal"], "port": 80, "meta": {"title": "Pi-hole", "description": "A <a href=https://github.com/pi-hole/docker-pi-hole>dockerized DNS server</a> which blocks ads with a web interface."}}}'
exec /s6-init
# For DHCP it is recommended to remove these ports and instead add: network_mode: "host"
#ports:
# - "53:53/tcp"
# - "53:53/udp"
# - "80:80/tcp"
cap_add:
- NET_ADMIN
environment:
TZ: "${PIHOLE_TZ:-America/New_York}"
WEBPASSWORD: "${PIHOLE_WEBPASSWORD:-}"
volumes:
- ./consul:/usr/local/bin/consul
- ./jq:/usr/local/bin/jq
- ./scripts/consul-agent.sh:/bin/consul-agent.sh
- 'etc-pihole:/etc/pihole'
- 'etc-pihole-dnsmasq:/etc/dnsmasq.d'
networks:
internal:
ipv4_address: 172.16.238.250
#create a DNS service which also forwards lookups to consul DNS
dnsmasq: &dnsmasq
build:
network: host
context: .
dockerfile_inline: |
FROM alpine
RUN apk --no-cache add dnsmasq \
&& echo "conf-dir=/etc/dnsmasq,*.conf" > /etc/dnsmasq.conf
EXPOSE 53/tcp 53/udp
#VOLUME ["/etc/dnsmasq"]
CMD ["dnsmasq"]
init: true
deploy:
replicas: 1
restart_policy:
condition: any
dns:
- 172.16.238.250
command:
- /bin/sh
- -c
- |
set -ex
type curl || (
until apk update; do sleep 3; done
until apk add curl bind-tools; do sleep 3; done
)
echo '{{range service "consul"}}server=/consul.service.consul/{{.Address}}#8600' >> /tmp/dnsmasq.tpl
echo '{{end}}' >> /tmp/dnsmasq.tpl
consul-agent.sh --service '{"service": {"name": "dnsmasq", "tags": [], "port": 53}}' \
--consul-template-file-cmd /tmp/dnsmasq.tpl dnsmasql.tpl /etc/dnsmasq/consul.conf "consul lock -name=service/dnsmasq -shell=false restart killall dnsmasq"
# end consul-template template
set +e
while true; do
sleep 1
CONSUL_IP="`dig +short consul | tail -n1`"
# add --log-queries for more verbosity
dnsmasq --no-daemon --server=/consul/"$${CONSUL_IP}"#8600
done
volumes:
- ./consul-template:/usr/local/bin/consul-template
- ./consul:/usr/local/bin/consul
- ./jq:/usr/local/bin/jq
- ./scripts/consul-agent.sh:/bin/consul-agent.sh
- dnsmasq-1:/etc/dnsmasq
cap_add:
- NET_ADMIN
networks:
internal:
ipv4_address: 172.16.238.252
dnsmasq-secondary:
<<: *dnsmasq
volumes:
- ./consul-template:/usr/local/bin/consul-template
- ./consul:/usr/local/bin/consul
- ./jq:/usr/local/bin/jq
- ./scripts/consul-agent.sh:/bin/consul-agent.sh
- dnsmasq-2:/etc/dnsmasq
networks:
internal:
ipv4_address: 172.16.238.251
dns-troubleshoot:
image: joffotron/docker-net-tools
init: true
restart: always
deploy:
replicas: 0
networks:
- internal
dns:
- 172.16.238.251
- 172.16.238.252
depends_on:
- dnsmasq
consul:
image: 'consul:1.11.2'
init: true
restart: always
command: 'agent -datacenter docker -server -bootstrap-expect 3 -disable-host-node-id -client 0.0.0.0 -ui -data-dir /consul/data'
healthcheck:
test: ['CMD', '/bin/sh', '-c', 'curl -sfLo /dev/null http://127.0.0.1:8500/v1/health/node/$$HOSTNAME']
deploy:
replicas: 1
restart_policy:
condition: any
dns:
- 172.16.238.251
- 172.16.238.252
volumes:
- consul-leader:/consul/data
depends_on:
- dnsmasq
networks:
internal:
ipv4_address: 172.16.238.249
consul-worker-1: &consul-worker
image: 'consul:1.11.2'
init: true
command: 'agent -datacenter docker -server -join consul -disable-host-node-id -client 0.0.0.0 -ui -data-dir /consul/data'
volumes:
- consul-worker-1:/consul/data
deploy:
replicas: 1
restart_policy:
condition: any
dns:
- 172.16.238.251
- 172.16.238.252
networks:
internal:
ipv4_address: 172.16.238.248
consul-worker-2:
<<: *consul-worker
volumes:
- consul-worker-2:/consul/data
networks:
internal:
ipv4_address: 172.16.238.247
vault:
image: 'vault:1.9.3'
init: true
#exports work around vault bug https://github.com/hashicorp/vault/issues/3866
#IP is the IP address of the default networking route
#$$ escapes in "$" in docker-compose string interpolation
command:
- "sh"
- "-c"
- |
set -ex
export IP=$$(ip -o ro get $$(ip ro | awk '$$1 == "default" { print $$3 }') | awk '{print $$5}')
export VAULT_API_ADDR="http://$${IP}:8200" VAULT_CLUSTER_ADDR="https://$${IP}:8201"
exec vault server -config=/vault/config
#set scale: 3 for HA configuration
deploy:
replicas: 1
restart_policy:
condition: any
volumes:
- vault-file:/vault/file
- vault-logs:/vault/logs
environment:
VAULT_ADDR: 'http://127.0.0.1:8200'
VAULT_LOCAL_CONFIG: >-
{
"ui": true,
"backend": {
"consul": {
"address": "consul:8500",
"path": "vault",
"scheme": "http"
}
},
"default_lease_ttl": "168h",
"listener": {
"tcp": {
"address": "0.0.0.0:8200",
"tls_disable": "1"
}
},
"max_lease_ttl": "720h"
}
cap_add:
- IPC_LOCK
networks:
internal:
ipv4_address: 172.16.238.246
dns:
- 172.16.238.251
- 172.16.238.252
depends_on:
- consul-worker-1
- consul-worker-2
- consul
portal:
image: nginx
init: true
deploy:
replicas: 1
restart_policy:
condition: any
networks:
- internal
dns:
- 172.16.238.251
- 172.16.238.252
depends_on:
- consul-worker-1
- consul-worker-2
- consul
volumes:
- ./consul-template:/usr/local/bin/consul-template
- ./templates/nginx.conf:/nginx.conf
- ./templates/index.html:/index.html
- ./consul:/usr/local/bin/consul
- ./jq:/usr/local/bin/jq
- ./scripts/consul-agent.sh:/bin/consul-agent.sh
command:
- /bin/sh
- -cx
- |
# this command will automatically register the portal app as a consul service
type curl || (
until apt-get update; do sleep 3; done
until apt-get -y --no-install-recommends install unzip curl ca-certificates procps less vim; do sleep 3; done
)
curl -fLo /usr/share/nginx/html/stylesheet.css https://raw.githubusercontent.com/samrocketman/jervis-api/gh-pages/1.6/stylesheet.css
curl -fLo ~/.vimrc https://raw.githubusercontent.com/samrocketman/home/master/dotfiles/.vimrc
until curl -sSfIo /dev/null http://consul:8500/ui/; do sleep 1;done
consul-agent.sh --service '{"service": {"name": "portal", "tags": [], "port": 80}}' \
--consul-template-file-cmd /nginx.conf nginx.tpl /etc/nginx/conf.d/default.conf "consul lock -name service/portal -shell=false reload nginx -s reload" \
--consul-template-file /index.html index.html.tpl /usr/share/nginx/html/index.html
exec nginx -g 'daemon off;'
socks:
# socks5 proxy service for browsers to connect into the network
# https://github.com/serjs/socks5-server
image: serjs/go-socks5-proxy
init: true
restart: always
deploy:
replicas: 0
restart_policy:
condition: any
ports:
- "127.0.0.1:1080:1080"
networks:
- internal
dns:
- 172.16.238.251
- 172.16.238.252
depends_on:
- dnsmasq