What I am trying to do:
I have a docker-compose file with 4 containers traefik, UI, API and DB.
I want to use traefik to redirect both containers UI and API to port 80 but on a different url path. UI is redirected directly to localhost:80 and API I want to redirect to localhost/api, but the problem is that localhost/api is already taken in the UI container by valid html code. So I need to exclude it from the API routing or provide a valid PathRegexp which I am failing to create.
Here is the docker-compose where Iam trying PathRegexp:
Idea is to redirect only api endpointslike /api/endpoint1 or /api/endpoint2 but not redirect /api itself as that one I need to be redirected to UI container.
version: "3"
services:
api:
build:
context: .
dockerfile: ./api/dockerfile
depends_on:
- db
- traefik
labels:
- "traefik.http.routers.api.rule=Host(`localhost`) && PathRegexp(`^/api/.*`)"
ports:
- 5000:5000
ui:
build:
context: .
dockerfile: ./ui/dockerfile
depends_on:
- api
- db
- traefik
volumes:
- ./ui/html/:/var/www/html
labels:
- "traefik.http.routers.ui.rule=Host(`localhost`)"
ports:
- 81:81
- 443:443
db:
image: mysql
restart: always
env_file: .env
environment:
MYSQL_ROOT_PASSWORD: $ROOT_PASS_MYSQL
MYSQL_DATABASE: $PRACTICE_DB
ports:
- 3307:3306
volumes:
- ./db/mysql:/docker-entrypoint-initdb.d/:ro
traefik:
image: traefik:v2.9
command: --api.insecure=true --providers.docker
ports:
- 80:80
- 8080:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
With this configuration I am getting an error:
error while parsing rule Host(localhost) && PathRegexp(^/api/.*): unsupported function: PathRegexp