I want to run my ASP.NET Core web api server and fluentd for its logging driver with docker-compose. My docker-compose.yml is like below.
version: "2"
services:
web:
build:
context: ..
dockerfile: ./DockerTest/Dockerfile
container_name: web
depends_on: [ fluentd ]
networks:
test_net:
ipv4_address: 172.20.10.1
ports:
- "8080:80"
logging:
driver: fluentd
options:
fluentd-address: 172.20.10.4:24224
tag: "web.log"
fluentd:
build:
context: ./fluentd
dockerfile: Dockerfile
container_name: fluentd
volumes:
- ./fluentd/conf:/fluentd/etc
networks:
test_net:
ipv4_address: 172.20.10.4
ports:
- "24224:24224"
- "24224:24224/udp"
networks:
test_net:
ipam:
config:
- subnet: 172.20.0.0/16
If I run web server after fluentd is fully executed, it works fine. But if I run with command docker-compose up, my web server is started before fluentd makes following logs.
[info]: #0 listening port port=24224 bind="0.0.0.0"
[info]: #0 fluentd worker is now running worker=0
So the web server fails to start with error.
Error response from daemon: failed to initialize logging driver: dial tcp 172.20.10.4:24224: connect: connection refused.
I tried to add depends_on and links, but both are not working.
I solved this using
fluentd-async-connectoption.It will try to re-connect after each connection fail.