I'm working with what I think is a pretty basic example but cannot seem to get it configured correctly.
I'm using docker-compose and using Traefik as a reverse proxy. Here is my docker-compose.yaml
version: "3.8"
services:
reverse-proxy:
# The official v2 Traefik docker image
image: traefik:v2.2
# Enables the web UI and tells Traefik to listen to docker
command:
- "--api.insecure=true"
- "--providers.docker"
- "--providers.docker.exposedByDefault=false"
ports:
# The HTTP port
- "80:80"
# The Web UI (enabled by --api.insecure=true)
- "8080:8080"
volumes:
# So that Traefik can listen to the Docker events
- /var/run/docker.sock:/var/run/docker.sock
account:
build:
context: ./accounts
target: builder
image: account
expose:
- "8080"
labels:
- "traefik.enable=true"
- "traefik.http.routers.account.rule=Host(`example.com`) && PathPrefix(`/api/accounts`)"
environment:
- ENV=dev
I have example.com
mapped in my hosts file to 127.0.0.1
and when I access http://example.com:8080/api/rawdata
I do get the traefik config.
But if I try accessing my service, http://example.com/api/accounts
I get a 404 page not found
. My account service is a Go server listening on :8080
and I have the expose
key in my compose file.
Here is the output of going to the traefik api
{
"routers": {
"account@docker": {
"entryPoints": [
"http"
],
"service": "account-example",
"rule": "Host(`example.com`) && PathPrefix(`/api/accounts`)",
"status": "enabled",
"using": [
"http"
]
},
"api@internal": {
"entryPoints": [
"traefik"
],
"service": "api@internal",
"rule": "PathPrefix(`/api`)",
"priority": 2147483646,
"status": "enabled",
"using": [
"traefik"
]
},
"dashboard@internal": {
"entryPoints": [
"traefik"
],
"middlewares": [
"dashboard_redirect@internal",
"dashboard_stripprefix@internal"
],
"service": "dashboard@internal",
"rule": "PathPrefix(`/`)",
"priority": 2147483645,
"status": "enabled",
"using": [
"traefik"
]
}
},
"middlewares": {
"dashboard_redirect@internal": {
"redirectRegex": {
"regex": "^(http:\\/\\/(\\[[\\w:.]+\\]|[\\w\\._-]+)(:\\d+)?)\\/$",
"replacement": "${1}/dashboard/",
"permanent": true
},
"status": "enabled",
"usedBy": [
"dashboard@internal"
]
},
"dashboard_stripprefix@internal": {
"stripPrefix": {
"prefixes": [
"/dashboard/",
"/dashboard"
]
},
"status": "enabled",
"usedBy": [
"dashboard@internal"
]
}
},
"services": {
"account-bretsblackapron@docker": {
"loadBalancer": {
"servers": [
{
"url": "http://192.168.224.5:8080"
}
],
"passHostHeader": true
},
"status": "enabled",
"usedBy": [
"account@docker"
],
"serverStatus": {
"http://192.168.224.5:8080": "UP"
}
},
"api@internal": {
"status": "enabled",
"usedBy": [
"api@internal"
]
},
"dashboard@internal": {
"status": "enabled",
"usedBy": [
"dashboard@internal"
]
},
"noop@internal": {
"status": "enabled"
}
}
}
I am able to access the service directly from http://192.168.224.5:8080
, but not from http://localhost/api/accounts
, or http://127.0.0.1/api/accounts
or http://example.com/api/accounts
.
Any help would be greatly appreciated.