Skip to content

Instantly share code, notes, and snippets.

@ilosamart
Last active January 12, 2018 15:26
Show Gist options
  • Save ilosamart/0fb0dd383d74e5bb75729599cf30bfda to your computer and use it in GitHub Desktop.
Save ilosamart/0fb0dd383d74e5bb75729599cf30bfda to your computer and use it in GitHub Desktop.
TRÍADE DO SUCESSO (Consul+Registrator+Traefik)
# Para CentOS
# firewall-cmd --zone=public --add-port=53/udp --permanent
# firewall-cmd --zone=public --add-port=8500/tcp --permanent
# firewall-cmd --zone=public --add-port=80/tcp --permanent
# firewall-cmd --zone=public --add-port=443/tcp --permanent
# firewall-cmd --reload
# Lembrando que há isolamento entre redes Docker, ler:
# https://docs.traefik.io/user-guide/docker-and-lets-encrypt/#networking
docker network create traefik
# TRÍADE DO SUCESSO (Consul+Registrator+Traefik)
# 1- Traefik
docker run -d --restart=always --name traefik \
-p 8080:8080 -p 80:80 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $PWD/traefik.toml:/etc/traefik/traefik.toml \
--network=traefik \
traefik
MEU_IP=`ip addr show | grep -P "inet.*?$(ip route show | grep -P '^default' | awk '{ print $5 }')" | awk '{ print $2 }' | cut -d'/' -f1`
# 2- Registrator
#Não consegui passaro valor de MEU_IP para o container, então rolou uma gambiarra
eval echo docker run -d \
--name=registrator \
--restart=always \
--net=host \
--volume=/var/run/docker.sock:/tmp/docker.sock \
gliderlabs/registrator:latest \
-ip=${MEU_IP} consul://127.0.0.1:8500
# 3 - Consul
docker run \
-d \
--name=consul \
--restart=always \
--net=host \
-e 'CONSUL_ALLOW_PRIVILEGED_PORTS=' \
-e CONSUL_LOCAL_CONFIG='{
"datacenter":"local",
"server":true,
"enable_debug":true
}' \
consul agent -server -ui -bootstrap-expect=1 -dns-port=53 -domain=dev.mp.rs.gov.br -recursor=172.17.1.242 -bind=127.0.0.1 -client=0.0.0.0
# Serviço de exemplo (apache)
docker run --rm -P --name fabio -e=SERVICE_80_NAME=fabio --label traefik.frontend.rule="HostRegexp:{subdomain:fabio.*}" httpd:alpine
cp /etc/resolv.conf cp /etc/resolv.conf.bkp
echo 'nameserver 127.0.0.1
search mp.rs.gov.br
search mprs.mp.br
search service.consul
' > /etc/resolv.conf
################################################################
# Global configuration
################################################################
# Enable debug mode
#
# Optional
# Default: false
#
debug = true
# Log level
#
# Optional
# Default: "ERROR"
#
# logLevel = "ERROR"
# Entrypoints to be used by frontends that do not specify any entrypoint.
# Each frontend can specify its own entrypoints.
#
# Optional
# Default: ["http"]
#
# defaultEntryPoints = ["http", "https"]
defaultEntryPoints = ["http"]
# Entrypoints definition
#
# Optional
# Default:
[entryPoints]
[entryPoints.http]
address = ":80"
# Traefik logs
# Enabled by default and log to stdout
#
# Optional
#
# [traefikLog]
# Sets the filepath for the traefik log. If not specified, stdout will be used.
# Intermediate directories are created if necessary.
#
# Optional
# Default: os.Stdout
#
# filePath = "log/traefik.log"
# Format is either "json" or "common".
#
# Optional
# Default: "common"
#
# format = "common"
# Enable access logs
# By default it will write to stdout and produce logs in the textual
# Common Log Format (CLF), extended with additional fields.
#
# Optional
#
# [accessLog]
# Sets the file path for the access log. If not specified, stdout will be used.
# Intermediate directories are created if necessary.
#
# Optional
# Default: os.Stdout
#
# filePath = "/path/to/log/log.txt"
# Format is either "json" or "common".
#
# Optional
# Default: "common"
#
# format = "common"
################################################################
# Web configuration backend
################################################################
# Enable web configuration backend
[web]
# Web administration port
#
# Required
#
address = "0.0.0.0:8080"
################################################################
# Docker configuration backend
################################################################
# Enable Docker configuration backend
[docker]
# Docker server endpoint. Can be a tcp or a unix socket endpoint.
#
# Required
# Default: "unix:///var/run/docker.sock"
#
# endpoint = "tcp://10.10.10.10:2375"
# Default domain used.
# Can be overridden by setting the "traefik.domain" label on a container.
#
# Optional
# Default: ""
#
# domain = "docker.localhost"
# Expose containers by default in traefik
#
# Optional
# Default: true
#
# exposedbydefault = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment