Post

Streamlined Traefik Installation With An Script

Why Use This Script?

Setting up Traefik as a reverse proxy for your Docker environment can seem daunting. However, this script simplifies the process by automating key steps such as file creation, permissions, and deployment using Docker Compose.

Inspired by Techno Tim’s Traefik guide, this script provides a quick and efficient way to get started. For a more in-depth understanding, be sure to check out his comprehensive tutorial.


Prerequisites

Before you run the script, ensure you complete the following on your Traefik VM:

1. Create the Necessary Folder Structure

1
2
sudo mkdir -p ~/traefik/data
cd ~/traefik

2. Download Configuration Files

Download these files from the repository and place them in the respective locations:

3. Folder Structure Overview

After downloading the files, your folder structure should look like this:

1
2
3
4
5
6
7
~/traefik
├── data
│   ├── config.yml
│   └── traefik.yml
├── cf_api_token.txt
├── docker-compose.yml
└── setup-traefik.sh

4.Configuring the Files

Here’s a breakdown of the files and how to adjust them:

1. config.yml

Contains router configurations. Customize it to include your services, such as a Proxmox setup.

2. traefik.yml

The core Traefik configuration file. Review to ensure it meets your needs.

3. cf_api_token.txt

Stores your Cloudflare DNS API token. To generate the token:

  1. Log in to Cloudflare and navigate to My Profile → API Tokens.
  2. Create a new API token with these permissions:
    • Zone → Zone → Read
    • Zone → DNS → Edit
  3. Add a rule under Zone Resources:
    • Include → Specific Zone → YourDomain
  4. Add an optional IP filter:
    • Client IP Address Filtering → Is In → YourPublicIP
  5. Copy the token and paste it into cf_api_token.txt.

4. docker-compose.yml

No changes are necessary unless you have specific customizations.

5. setup-traefik.sh

Modify the following variables in the script to match your setup:

1
2
3
4
5
6
# Set variables
TRAFFIK_DIR="$HOME/traefik"     # Traefik directory
DATA_DIR="$HOME/traefik/data"   # Data directory
LINUX_USER="docker-user"        # Linux user with Docker access
USER="your_dashboard_user"      # Dashboard username
PASSWORD="your_dashboard_password" # Dashboard password

Running the Script

Make the script executable and run it:

1
2
chmod +x setup-traefik.sh
./setup-traefik.sh

Post-Setup Check

  1. Verify that Traefik is running:
    1
    
    sudo docker logs traefik
    
  2. Check for the acme.json file in the ~/traefik/data folder to confirm that certificates were generated successfully.

Conclusion

Congratulations! You’ve successfully set up Traefik using the script. With minimal manual effort, you now have a fully functional reverse proxy that integrates seamlessly with Docker and Cloudflare.

For further troubleshooting or advanced configurations, revisit the Techno Tim guide.

This post is licensed under CC BY 4.0 by the author.