Traefik docker-compose configuration with secure dashboard and Let’s Encrypt

This configuration only provides only the minimum to get the Traefik Dashboard running with Let’s Encrypt-driven SSL encryption and user authentication. It also redirects all HTTP requests to HTTPS in order to avoid insecure access to the Dashboard and other services.

Let’s encrypt is used with the HTTP-01 challenge. This means that Traefik MUST be reachable by Port 80 from the Internet.

In order to install docker & docker-compose, see How to install docker and docker-compose on Ubuntu in 30 seconds.

First prepare the directory (/var/lib/traefik):

sudo mkdir /var/lib/traefik
sudo chown -R $USER: /var/lib/traefik
cd /var/lib/traefik
mkdir acme conf

Now create docker-compose.yml:

version: "3.3"

    image: "traefik:v2.3"
    container_name: "traefik"
      - "--api=true"
      - "80:80"
      - "443:443"
      - "8080:8080"
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./acme:/etc/traefik/acme"
      - "./traefik.toml:/etc/traefik/traefik.toml"
      - "./conf:/etc/traefik/conf"

Now create the main traefik.toml configuration file:

defaultEntryPoints = ["http", "https"]

dashboard = true

# You can create config files in /var/lib/traefik/traefik.conf and Traefik will automatically reload them
directory = "/etc/traefik/conf/"
watch = true

# Change this to INFO if you don't want as much debug output
level = "DEBUG"

address = ":80"
to = "websecure"
scheme = "https"
address = ":443"

# TODO Add your email here
email = "[email protected]"
storage = "/etc/traefik/acme/acme.json"
entryPoint = "web"

Now we need to create the API config file in conf/api.toml:

# TODO: Set your domain here !!!
rule = "Host(``)"
service = "[email protected]"
middlewares = ["auth"]
certresolver = "letsencrypttls"
# TODO Add your admin user & password here, generate e.g. using
users = [

Don’t forget to change your email address and the domain name in the config files (marked by TODO). Ensure you have setup all DNS records correctly so that your domains points to the server running Traefik!

Now it’s time to startup Traefik for the first time:

docker-compose up

Traefik will take a few seconds to automatically generate the Let’s Encrypt certificate for your domain. Once you see a message like

traefik    | time="2020-09-20T23:48:30Z" level=debug msg="Certificates obtained for domains []" providerName=letsencrypttls.acme [email protected] rule="Host(``)"

the certificate is available and loaded automatically.

Now you can go to , login with the username and password you have generated and check out the dashboard.


If desired, you can also setup a systemd service to automatically start Traefik on boot (generated using docker-compose systemd .service generator). In order to do this, first stop the running docker-compose instance using Ctrl-C if you still have the terminal open and docker-compose down.

Now add this as /etc/systemd/system/traefik.service:


# Shutdown container (if running) when unit is stopped
ExecStartPre=/usr/local/bin/docker-compose -f docker-compose.yml down -v
# Start container when unit is started
ExecStart=/usr/local/bin/docker-compose -f docker-compose.yml up
# Stop container when unit is stopped
ExecStop=/usr/local/bin/docker-compose -f docker-compose.yml down -v


and run

sudo systemctl enable traefik.service
sudo systemctl start traefik.service


Posted by Uli Köhler in Traefik

How to fix Traefik Dashboard/API 404 page not found “api is not enabled”


You are trying to configure the Traefik API/Dashboard in a secure way, but every time you try to access the API, you’re only getting a 404 error (unless you set api.insecure=true)

In the logs, you see an error message like this: (if log.level = "DEBUG"):

traefik    | time="2020-09-20T22:53:51Z" level=error msg="api is not enabled" [email protected] entryPointName=websecure


You have to pass --api=true to Traefik, e.g. using docker-compose:

  - "--api=true"

and also set

dashboard = true

in your traefik.toml.

After that, restart Traefik and you should be able to access your dashboard at /dashboard.

Credits to multiple GitHub users for the original solution.

Posted by Uli Köhler in Traefik

How to fix Traefik “command traefik error: field not found, node: dnsProvider”


You are trying to configure your Traefik server but you see an error message like

traefik    | 2020/09/20 22:07:11 command traefik error: field not found, node: dnsProvider


dnsProvider is a configuration option from Traefik 1.x. You need to use provider for Traefik 2.x. Example:

provider = "cloudflare"

Full example:

email = "[email protected]"
storage = "/etc/traefik/acme/acme.json"

provider = "cloudflare"



Posted by Uli Köhler in Traefik