Skip to content

Instantly share code, notes, and snippets.

@Davidblkx
Last active September 14, 2019 20:41
Show Gist options
  • Save Davidblkx/9915a26b28b7ffd39aed38fc25e67c4b to your computer and use it in GitHub Desktop.
Save Davidblkx/9915a26b28b7ffd39aed38fc25e67c4b to your computer and use it in GitHub Desktop.
Install traefik for DOCKER + LET'S ENCRYPT
#!/bin/bash
# Install traefik for DOCKER + LET'S ENCRYPT
# RUN (./start.sh [DOMAIN] [EMAIL]) or change domain and email vars
DOMAIN=$1
EMAIL=$2
echo "running config for domain: ${DOMAIN} and email: ${EMAIL}"
read -p "Are you sure? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi
docker network create web
mkdir -p /opt/traefik
touch /opt/traefik/docker-compose.yml
touch /opt/traefik/acme.json && chmod 600 /opt/traefik/acme.json
touch /opt/traefik/traefik.toml
tee /opt/traefik/docker-compose.yml << EOF
version: '3'
services:
traefik:
image: traefik:1.7
restart: always
command: --api --docker
ports:
- 80:80
- 443:443
- 9000:8080
networks:
- web
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /opt/traefik/traefik.toml:/traefik.toml
- /opt/traefik/acme.json:/acme.json
container_name: traefik
networks:
web:
external: true
EOF
tee /opt/traefik/traefik.toml << EOF
debug = false
logLevel = "ERROR"
defaultEntryPoints = ["https","http"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[retry]
[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "${DOMAIN}"
watch = true
exposedByDefault = false
[acme]
email = "${EMAIL}"
storage = "acme.json"
entryPoint = "https"
onHostRule = true
[acme.httpChallenge]
entryPoint = "http"
EOF
cd /opt/traefik
docker-compose up -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment