I have the following and basic docker setup where the factory-service
creates a continues dataflow which is exposed through Fast API and shall be consumed by another container verification-service
. Between both container I want to use Traefik to function as Load Balancer.
I'm able to consume the data stream directly using http://localhost:8001/stream
. But unfortunately I'm not able to consume the stream in the verification-service
container. I'm stuck with the same issue for weeks now and don't know what to do anymore.. I'm new to Traefik and Docker
Fast API in factory-service
async def stream_data():
return StreamingResponse(generate_sensor_data(), media_type="text/event-stream")
verification-service
print("Connecting ...")
try:
response = requests.get("http://factory.local/stream", stream=True)
print(response.status_code, response.text)
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
Docker-Compose
factory-service:
build:
context: ./factory
dockerfile: Dockerfile
container_name: factory_service
ports:
- "8001:8001"
labels:
- "traefik.enable=true"
- "traefik.http.routers.factory.rule=Host(`factory.local`)"
- "traefik.http.services.factory.loadbalancer.server.port=8001"
- "traefik.docker.network=app-network"
networks:
app-network:
aliases:
- "factory.local"
verification-service:
build:
context: ./verification
dockerfile: Dockerfile
container_name: verification_service
depends_on:
factory-service:
condition: service_started
labels:
- "traefik.enable=true"
- "traefik.http.routers.verification.rule=Host(`verification.local`)"
- "traefik.docker.network=app-network"
networks:
- app-network
traefik:
image: traefik:v3.3
command:
- "--log.level=DEBUG"
- "--api.insecure=true"
- "--providers.docker"
- "--providers.docker.exposedbydefault=false"
- "--entryPoints.web.address=:80"
ports:
- "80:80"
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
- app-network
networks:
app-network:
driver: bridge
name: app-network