Skip to content

Instantly share code, notes, and snippets.

@chanux chanux/traefik-basic.md
Last active Aug 22, 2019

Embed
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"

[web]
address = ":8080"

[docker]
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 \
    emilevauge/traefik

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 127.0.0.1 in /etc/hosts file)

Example 2

docker run -d \
    --label=traefik.frontend.rule=Host:app2.dev \
    -v /path/to/my/content:/content \ 
    -p 8082:80 \
    larsks/thttpd -d /content

You can access this as app2.dev (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/127.0.0.1 and address=/docker.local/127.0.0.1 to /etc/dnsmasq.conf and restart dnsmasq

sudo service dnsmasq restart

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

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

@thepenguinthatwants

This comment has been minimized.

Copy link

commented Jun 10, 2019

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

@chanux

This comment has been minimized.

Copy link
Owner Author

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
You can’t perform that action at this time.