Skip to content

Instantly share code, notes, and snippets.



Last active Sep 13, 2020
What would you like to do?
Traefik quick setup

Traefik quick setup

This is a bare minimum guide to try traefik with Docker.

Create traefik.toml file with preferred configuration

port = ":80"

address = ":8080"

endpoint = "unix:///var/run/docker.sock"
domain = "docker.local"
watch = true

Run Traefik using docker

docker run -d \
    -p 80:80 \
    -p 8080:8080 \
    -v $PWD/traefik.toml:/traefik.toml \
    -v /var/run/docker.sock:/var/run/docker.sock \

Run example backends

Example 1

docker run -d \
    -v /path/to/my/content:/content \ 
    -p 8081:80 \
    --name app1 \
    larsks/thttpd -d /content

You can acces this as app1.docker.local (You'd have to point docker.local to in /etc/hosts file)

Example 2

docker run -d \ \
    -v /path/to/my/content:/content \ 
    -p 8082:80 \
    larsks/thttpd -d /content

You can access this as (You need to update /etc/hosts)

Convenient DNS resolution

Having to add all .dev or .docker.local domains to /etc/hosts is a pain. You can easily do that with dnsmasq.

sudo apt-get install dnsmasq

Now append address=/dev/ and address=/docker.local/ to /etc/dnsmasq.conf and restart dnsmasq

sudo service dnsmasq restart

Now all *.dev and *.docker.local domains will be pointed to, which in our case will be handled by Traefik.

PS: Use .test instead of .dev just because.


This comment has been minimized.

Copy link

@thepenguinthatwants thepenguinthatwants commented Jun 10, 2019

Adding address=/dev/ on etc/dnsmasq.conf doesnt seem to work for me.
Are there any good ways to debug+


This comment has been minimized.

Copy link
Owner Author

@chanux chanux commented Jun 12, 2019

See if this helps.

(Not relevant to the dnsmasq question but when I wrote this, Traefik was in it's infancy. Things might have changed :).)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment