The yaml file looks good at first sight.
You called it traefik.yml - so is this code snippet part of the static configuration file?
Defining routers and services are part of the dynamic configuration - so this should be defined in an extra file as a part of the file provider.
Another idea - are the docker container 'caddy' and traefik in the same docker network?
You've mounted traefik.yml to /traefik.yml in the container.
I assume traefik looks for the config file in /etc/traefik.
I suggest adding a few lines to your configuration:
define an external network. All containers which offer services to be routed with traefik, should be in this same network: docker network create traefik-servicenet
add a dynamic configuration (file provider) to your traefik setup, see example below.
docker-compose.yaml:
services:
traefik:
container_name: traefik
image: traefik:2.5 # version pinning is a good idea
restart: unless-stopped
ports:
- 80:80
- 8000:8080
volumes:
- /opt/appdata/traefik/traefik.yml:/etc/traefik/traefik.yml # changed the target file path
- /opt/appdata/traefik/dynamic.yml:/etc/traefik/dynamic.yml
- /var/run/docker.sock:/var/run/docker.sock:ro
labels:
- traefik.http.routers.traefik.service=api@internal
networks:
- traefik-servicenet
networks:
traefik-servicenet:
external: true
name: traefik-servicenet
The difference between the static configuration and the dynamic documenation is:
First, the static configuration is loaded once and cannot be changed in the runtine. It's the configuration of traefik itself.
Then, the dynamic configuration can easily be changed while running, so you can add or delete routers, services, middlewares without restarting traefik.
The dynamic configuration can be done with various ways (different providers), for example:
file provider (in this case the dynamic.yml)
docker provider (the docker socket, configuration by container labels)
kubernetes, ...
Please excuse my bad grammar. English is not my foreign language.