├── .gitignore ├── LICENSE ├── README.md ├── acdct └── examples ├── .gitignore ├── generated ├── .env ├── .htpasswd └── compose.yaml └── whoami ├── .env ├── README.md └── compose.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | .htpasswd 3 | compose.yml 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ISC License (ISC) 2 | 3 | Copyright 2020-2025 Eingress Ltd 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker Compose Traefik + Lets Encrypt + Cloudflare 2 | 3 | A docker compose configuration generator script for [Traefik](https://traefik.io/) with the [Lets Encrypt DNS-01 challenge](https://letsencrypt.org/docs/challenge-types/#dns-01-challenge) supported through [Cloudflare](cloudflare.com). 4 | 5 | ## Usage 6 | 7 | Generate the required compose, environment variable, and password files using ```acdct``` (current Traefik versions may be edited at the top of this file) 8 | 9 | ```sh 10 | ./acdct 11 | ``` 12 | 13 | Place compose.yaml, .env, and .htpasswd in your chosen directory, then 14 | 15 | ```sh 16 | docker compose pull 17 | docker compose up -d 18 | ``` 19 | 20 | ## Important 21 | 22 | Comment out the following line in ```compose.yaml``` for production. 23 | 24 | ```yml 25 | - --certificatesresolvers.letsencrypt.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory 26 | ``` 27 | 28 | See [examples](examples/) for how to configure services, and an example of generated output. 29 | -------------------------------------------------------------------------------- /acdct: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Acme Cloudflare Docker Compose Traefik generator 4 | 5 | # Edit as necessary 6 | 7 | TRAEFIK_IMAGE_VERSION=v3.3 8 | 9 | # DO NOT EDIT BELOW THIS LINE 10 | 11 | pushd() { 12 | command pushd "$@" >/dev/null 13 | } 14 | 15 | popd() { 16 | command popd "$@" >/dev/null 17 | } 18 | 19 | WORK_DIR="${1:-$(pwd)}" 20 | 21 | read -p 'Enter the Traefik dashboard host name e.g. traefik.eingress.io: ' HOST 22 | read -p 'Enter the Cloudflare account email address: ' CF_EMAIL 23 | read -p 'Enter the Cloudflare DNS api token: ' CF_TOKEN 24 | read -p 'Enter the Traefik dashboard user name: ' USER 25 | 26 | PASSWORD=$(openssl passwd -apr1) 27 | 28 | mkdir -p $WORK_DIR 29 | pushd $WORK_DIR 30 | 31 | echo '' | tee .env .htpasswd 32 | 33 | echo "CF_API_EMAIL=${CF_EMAIL}" >>.env 34 | echo "CF_API_TOKEN=${CF_TOKEN}" >>.env 35 | echo "HOST_NAME=${HOST}" >>.env 36 | echo "TRAEFIK_IMAGE=traefik:${TRAEFIK_IMAGE_VERSION}" >>.env 37 | 38 | echo "$USER:$PASSWORD" >>.htpasswd 39 | 40 | cat <<-EOF >compose.yaml 41 | 42 | networks: 43 | global: 44 | 45 | services: 46 | 47 | main: 48 | 49 | command: 50 | - --api=true 51 | - --api.dashboard=true 52 | 53 | - --certificatesresolvers.letsencrypt.acme.dnschallenge.delaybeforecheck=0 54 | - --certificatesresolvers.letsencrypt.acme.dnschallenge.provider=cloudflare 55 | - --certificatesresolvers.letsencrypt.acme.dnschallenge.resolvers=1.1.1.1:53,8.8.8.8:53 56 | - --certificatesresolvers.letsencrypt.acme.dnschallenge=true 57 | 58 | - --certificatesresolvers.letsencrypt.acme.email=\${CF_API_EMAIL} 59 | - --certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json 60 | 61 | - --entrypoints.http.address=:80 62 | - --entrypoints.https.address=:443 63 | - --entryPoints.https.http3 64 | - --entryPoints.https.http3.advertisedport=443 65 | 66 | - --providers.docker=true 67 | 68 | # !!! IMPORTANT! Comment out or delete next line in production! !!! 69 | - --certificatesresolvers.letsencrypt.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory 70 | 71 | env_file: 72 | - ./.env 73 | 74 | environment: 75 | - CLOUDFLARE_DNS_API_TOKEN=\${CF_API_TOKEN} 76 | 77 | hostname: \${HOST_NAME} 78 | 79 | image: \${TRAEFIK_IMAGE} 80 | 81 | labels: 82 | - traefik.http.middlewares.auth.basicauth.usersFile=/etc/traefik/.htpasswd 83 | - traefik.http.middlewares.to-https.redirectscheme.scheme=https 84 | 85 | - traefik.http.routers.to-https.entrypoints=http 86 | - traefik.http.routers.to-https.middlewares=to-https 87 | - traefik.http.routers.to-https.rule=HostRegexp(\`{host:.+}\`) 88 | 89 | - traefik.http.routers.traefik.entrypoints=https 90 | - traefik.http.routers.traefik.middlewares=auth 91 | - traefik.http.routers.traefik.rule=Host(\`\${HOST_NAME}\`) 92 | - traefik.http.routers.traefik.service=api@internal 93 | - traefik.http.routers.traefik.tls.certresolver=letsencrypt 94 | - traefik.http.routers.traefik.tls=true 95 | 96 | networks: 97 | - global 98 | 99 | ports: 100 | - 80:80 101 | - 443:443/tcp 102 | - 443:443/udp 103 | 104 | restart: unless-stopped 105 | 106 | volumes: 107 | - .htpasswd:/etc/traefik/.htpasswd 108 | - /var/run/docker.sock:/var/run/docker.sock:ro 109 | 110 | - acme:/letsencrypt 111 | 112 | volumes: 113 | acme: 114 | EOF 115 | 116 | echo "Created .env, .htpasswd, and compose.yaml files in ${WORK_DIR}" 117 | echo "Goodbye" 118 | 119 | popd 120 | 121 | exit 0 122 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | !.env 2 | !.htpasswd 3 | !compose.yml -------------------------------------------------------------------------------- /examples/generated/.env: -------------------------------------------------------------------------------- 1 | CF_API_EMAIL=example@eingress.io 2 | CF_API_TOKEN=C95D1775-B43F-4CC3-9CC8-C385950E9A4F 3 | HOST_NAME=tfk.eingress.io 4 | TRAEFIK_IMAGE=traefik:v3.3 5 | -------------------------------------------------------------------------------- /examples/generated/.htpasswd: -------------------------------------------------------------------------------- 1 | 2 | example:$apr1$dvvV2meX$F7sNxJSg4T1Q/n9vkYBSQ0 3 | -------------------------------------------------------------------------------- /examples/generated/compose.yaml: -------------------------------------------------------------------------------- 1 | 2 | networks: 3 | global: 4 | 5 | services: 6 | 7 | main: 8 | 9 | command: 10 | - --api=true 11 | - --api.dashboard=true 12 | 13 | - --certificatesresolvers.letsencrypt.acme.dnschallenge.delaybeforecheck=0 14 | - --certificatesresolvers.letsencrypt.acme.dnschallenge.provider=cloudflare 15 | - --certificatesresolvers.letsencrypt.acme.dnschallenge.resolvers=1.1.1.1:53,8.8.8.8:53 16 | - --certificatesresolvers.letsencrypt.acme.dnschallenge=true 17 | 18 | - --certificatesresolvers.letsencrypt.acme.email=${CF_API_EMAIL} 19 | - --certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json 20 | 21 | - --entrypoints.http.address=:80 22 | - --entrypoints.https.address=:443 23 | - --entryPoints.https.http3 24 | - --entryPoints.https.http3.advertisedport=443 25 | 26 | - --providers.docker=true 27 | 28 | # !!! IMPORTANT! Comment out or delete next line in production! !!! 29 | - --certificatesresolvers.letsencrypt.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory 30 | 31 | env_file: 32 | - ./.env 33 | 34 | environment: 35 | - CLOUDFLARE_DNS_API_TOKEN=${CF_API_TOKEN} 36 | 37 | hostname: ${HOST_NAME} 38 | 39 | image: ${TRAEFIK_IMAGE} 40 | 41 | labels: 42 | - traefik.http.middlewares.auth.basicauth.usersFile=/etc/traefik/.htpasswd 43 | - traefik.http.middlewares.to-https.redirectscheme.scheme=https 44 | 45 | - traefik.http.routers.to-https.entrypoints=http 46 | - traefik.http.routers.to-https.middlewares=to-https 47 | - traefik.http.routers.to-https.rule=HostRegexp(`{host:.+}`) 48 | 49 | - traefik.http.routers.traefik.entrypoints=https 50 | - traefik.http.routers.traefik.middlewares=auth 51 | - traefik.http.routers.traefik.rule=Host(`${HOST_NAME}`) 52 | - traefik.http.routers.traefik.service=api@internal 53 | - traefik.http.routers.traefik.tls.certresolver=letsencrypt 54 | - traefik.http.routers.traefik.tls=true 55 | 56 | networks: 57 | - global 58 | 59 | ports: 60 | - 80:80 61 | - 443:443/tcp 62 | - 443:443/udp 63 | 64 | restart: unless-stopped 65 | 66 | volumes: 67 | - .htpasswd:/etc/traefik/.htpasswd 68 | - /var/run/docker.sock:/var/run/docker.sock:ro 69 | 70 | - acme:/letsencrypt 71 | 72 | volumes: 73 | acme: 74 | 75 | -------------------------------------------------------------------------------- /examples/whoami/.env: -------------------------------------------------------------------------------- 1 | DEFAULT_NETWORK=traefik_global 2 | HOST_NAME=whoami.example.com # EDIT AS REQUIRED 3 | IMAGE_NAME=containous/whoami:latest 4 | SERVICE_NAME=whoami 5 | -------------------------------------------------------------------------------- /examples/whoami/README.md: -------------------------------------------------------------------------------- 1 | # Example Traefik Service - containous/whoami 2 | 3 | Deploy an instance of [containous/whoami](https://hub.docker.com/r/containous/whoami). 4 | 5 | ## Usage 6 | 7 | ```sh 8 | docker compose up -d 9 | ``` 10 | -------------------------------------------------------------------------------- /examples/whoami/compose.yaml: -------------------------------------------------------------------------------- 1 | 2 | networks: 3 | default: 4 | external: 5 | name: ${DEFAULT_NETWORK} 6 | 7 | services: 8 | 9 | whoami: 10 | 11 | env_file: 12 | - ./.env 13 | 14 | hostname: ${HOST_NAME} 15 | 16 | image: ${IMAGE_NAME} 17 | 18 | labels: 19 | - traefik.http.routers.${SERVICE_NAME}.entrypoints=https 20 | - traefik.http.routers.${SERVICE_NAME}.rule=Host(`${HOST_NAME}`) 21 | - traefik.http.routers.${SERVICE_NAME}.tls.certresolver=letsencrypt 22 | - traefik.http.routers.${SERVICE_NAME}.tls=true 23 | 24 | restart: unless-stopped 25 | --------------------------------------------------------------------------------