Search code examples
dockergodocker-composefluentd

Docker-compose pulls an two images, an app and fluentd but no logs are sent to stdout for fluentd


I'm new fluentd and I'm using two docker images one image is fluentd and my other image is my webapp. The webapp is creating logs and fluentd is listening on a port with the in_forward type but logs are not being sent to stdout

Docker-compose.yml file

  dataporter:
    image: <app-docker>
    command: <associated command>
    ports:
      - 80:8080
    links:
      - fluentd
    logging:
      driver: "fluentd"
      options:
        fluentd-address: :24224
        tag: data-porter

  fluentd:
    image: <fluentd-docker>
    volumes:
      - ./fluentd.conf:/fluentd/etc/fluent.conf
    ports:
      - "24224:24224"

fluentd.conf file

<source>
  @type forward
  port 24224
  bind "0.0.0.0"
</source>

<match **>
   @type stdout
</match>

My app is in golang and I put some simple log statements with this package import log "github.com/sirupsen/logrus" and so my simple log statements are log.Info("Infof print") but no new logs are shown in fluentd docker container logs besides the initial start up statements.


Solution

  • The reason why the fluentd image was not seeing the logs was because the data-porter image needs fluentd to finish it's setup so although the data-porter container was running it couldn't properly connect to the fluentd container. In summary any container that needs to connect to fluentd needs to wait for fluentd to finish setting up. To fix the issue I had a script that stops the container relying on fluentd and starts it back up. Adding a container_name: <name> to the docker-compose.yml file for the services help with the script.

    docker-compose up -d
    sleep(3)
    docker stop <container-name-relying-on-fluentd>
    docker-compose up -d