Following this tutorial
version: '3.8'
services:
reverse-proxy:
container_name: traefik
image: traefik:v2.5
command:
- "--log.level=DEBUG"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
ports:
- "80:80"
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
whoami:
container_name: whoami
image: "traefik/whoami"
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.rule=Host(`whoami.vws.dev`)"
- "traefik.http.routers.whoami.entrypoints=web"
When trying on my browser, I can't get a response from :
CodePudding user response:
Nothing you configure in your docker-compose.yml
file can make your browser "know" how to map the name vws.dev
to your container. If you bring up your compose stack, you can verify it's working using curl
by explicitly setting the Host
header, like this:
curl -H 'Host: whoami.vws.dev` localhost:80
Which on my system prints something like:
Hostname: 65df3ef3b7d2
IP: 127.0.0.1
IP: 172.19.0.3
RemoteAddr: 172.19.0.2:43904
GET / HTTP/1.1
Host: whoami.vws.dev
User-Agent: curl/7.76.1
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.19.0.1
X-Forwarded-Host: whoami.vws.dev
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: 2b2a7ec697d6
X-Real-Ip: 172.19.0.1
If you want to be able to visit http://whoami.vws.dev
in your browser, you would have to somehow map that name to the container's ip address. On a unix-like system, you can generally do this by editing your /etc/hosts
file; for example, I could modify the entry for 127.0.0.1
by appending whoami.vws.dev
to the list of names:
127.0.0.1 localhost ... whoami.vws.dev
With that change, I can run:
$ curl whoami.vws.dev
Hostname: 65df3ef3b7d2
IP: 127.0.0.1
IP: 172.19.0.3
RemoteAddr: 172.19.0.1:43748
GET / HTTP/1.1
Host: whoami.vws.dev
User-Agent: curl/7.76.1
Accept: */*
For a "real" deployment, you would typically add a DNS entry mapping your desired hostname to the address of your docker host.