Traefik is a nice little product that makes it easy to deploy a reverse proxy for Docker containers. This document describes how to set up a Digital Ocean node, install Docker on it, run Traefik, and configure it to use Let's Encrypt for wildcard certificates.
Now that we have Docker running on the node, we need to run Traefik. This is probably the simplest step of all. But since we're running on the Internet, we can't just fire up Traefik - you'd want to protect at least the monitoring port.
We'll assume that all apps will be located under the ${USERDIR}/docker/ in their own folder.
To protect the Traefik monitoring UI, we'll use HTTP authentication.
-
Create a file
.htpasswdin${USERDIR}/docker/shared -
Create a strong username/password combo. You can use HTPASSWD Generator, or LastPass, or similar
-
Add the combo to
.htpasswdas follows:username:passwordwhere
usernameis your chosen username, andpasswordis the strong password generated by your utility of choice. -
Save the file and exit
TZ="America/New_York"
USERDIR="/home/USER"
HTTP_USERNAME=username
HTTP_PASSWORD=password
DOMAINNAME=example.com
TZis the timezone for your machine. Find your correct timezone in the timezone databaseUSERDIRis the path to the homefolder of the current user. ReplaceUSERwith your user ID.usernameis the username you created for the HTTP authenticationpasswordis the strong password you created for the HTTP authentication
Create folders for Traefik and ACME. With the ${USERDIR} environment variable set as above, run the following commands:
mkdir
Create an empty acme.json file for Traefik to use:
touch
We'll set up Traefik to use subdomains for the different apps that we want to run. Create ${USERDIR}/docker/traefik/traefik.toml with the contents of the following file:
Replace the following:
email@domain.comwith your email addressEXAMPLE.COMwith your domain name- You may have to enable the InsecureSkipVerify line to allow some apps access through Traefik
exposedbydefault = falseforces you to usetraefik.enable=truein docker compose to put apps behind traefik. If you would like to do this for all apps, change it to exposedbydefault to true.
Create a docker-compose.yml with the following content: