I am setting up a local Debian server with Docker and multiple containers/services. I am trying to point a subdomain to each container with Traefik, it doesn’t work and I don’t know where the problem is.
I have created traefik and test-only containers following this guide, but I get gateway timeout when I call curl foo.myserver.local
(see source code below).
# foo/docker-compose.yml
services:
foo:
image: httpd:alpine
container_name: foo
ports:
- '9999:80'
volumes:
- ./website:/usr/local/apache2/htdocs
labels:
- "traefik.enable=true"
- "traefik.http.routers.cal.rule=Host(`foo.myserver.local`)"
- "traefik.http.routers.cal.entrypoints=web"
- "traefik.http.services.cal.loadbalancer.server.port=9999"
Foo website:
# foo/website/index.html
Foo page
Traefik container:
# traefik/docker-compose.yml
services:
traefik:
image: traefik:v2.0
container_name: traefik
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
restart: unless-stopped
ports:
- "80:80"
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
Hosts file:
# /etc/hosts
127.0.0.1 localhost
192.168.3.17 myserver.local myserver
192.168.3.17 foo.myserver.local myserver
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
Some tests:
user@myserver:~$ curl myserver.local
404 page not found
user@myserver:~$ curl foo.myserver.local
Gateway Timeout
user@myserver:~$ curl 192.168.3.17
404 page not found
user@myserver:~$ curl 192.168.3.17:9999
Foo page
user@myserver:~$ curl localhost
404 page not found
user@myserver:~$ curl localhost:9999
Foo page