Hello,
I am having trouble sending HTTP requests from one service to another through Traefik.
I have two docker-compose.yml files, the first file defines Traefik and a first service (myapi
in which I implemented a minimalist FastAPI endpoint), and the second file defines a second service (myclient
which also includes a second FastAPI just to keep the container running).
Here is the first docker-compose.yml file, where I defined a web
entrypoint for Traefik using port 80, defined 127.0.0.1
as host and 80
as port and web
as entrypoint for myapi
, and setup a network.
version: '3'
services:
traefik:
image: traefik:v2.10
container_name: traefik
command:
- "--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
networks:
- mynetwork
myapi:
build:
context: .
dockerfile: Dockerfile
container_name: myapi
labels:
- "traefik.enable=true"
- "traefik.http.routers.myapi.rule=Host(`127.0.0.1`)"
- "traefik.http.routers.myapi.entrypoints=web"
- "traefik.http.services.myapi.loadbalancer.server.port=80"
networks:
- mynetwork
networks:
mynetwork:
Here is the second docker-compose.yml file, where I defined 127.0.0.1
as host and 82
as port and web
as entrypoint for myclient
, and attached myclient
to the Docker network.
services:
myclient:
build:
context: .
dockerfile: Dockerfile
container_name: myclient
labels:
- "traefik.enable=true"
- "traefik.http.routers.myclient.rule=Host(`127.0.0.1`)"
- "traefik.http.routers.myclient.entrypoints=web"
- "traefik.http.services.myclient.loadbalancer.server.port=82"
networks:
- myapi_mynetwork
networks:
myapi_mynetwork:
external: true
I can curl and send requests from the host machine to myapi
using http://127.0.0.1:80
. But when trying to curl myapi
from myclient
container with curl http://127.0.0.1:80
, I am getting (7) Failed to connect to 127.0.0.1 port 80 after 0 ms: Couldn't connect to server
.
I am new to Traefik and I am obviously making a mistake in my configuration? Any hint would be appreciated!
For information, this is a small reproductible example which imitates my actual use case. This actual use case consists in trying to send annotation requests from FiftyOne to CVAT.
I am trying to use Traefik for this, because CVAT docker-compose.yml already includes Traefik, but I am not even sure this is the right approach?
Many thanks in advance!