Docker – logging to Graylog2 container with GELF log-driver raises an error

I want to set up Docker system to run MongoDB, Elasticsearch, Graylog2 and my microservices and also forward all the logs to the Graylog server. I’ve made a docker-compose.yml file to run it altogether:

version: '2'

services:
    elasticsearch:
        image: "elasticsearch:2"
        command: "elasticsearch -Des.cluster.name='graylog'"
        volumes:
          - elasticsearch:/usr/share/elasticsearch/data
        ulimits:
          memlock:
            soft: -1
            hard: -1
          nofile:
            soft: 65536
            hard: 65536
        ports:
            - "9200:9200"
    graylog:
        image: graylog2/server:latest
        environment:
            GRAYLOG_PASSWORD_SECRET: somepasswordpepper
            GRAYLOG_ROOT_PASSWORD_SHA2: 8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918
            GRAYLOG_WEB_ENDPOINT_URI: http://127.0.0.1:9000/api
        links:
            - mongodb:mongo
            - elasticsearch:elasticsearch
        ports:
            - "9000:9000"
            - "12201/udp:12201/udp"
            - "1514/udp:1514/udp"

    mongodb:
        build: ./docker/mongo
        ports:
            - "27017:27017"
        volumes:
            - mongodb:/data/db

    omsevents:
        build:
            context: ./oms-events
        links:
            - mongodb
        logging:
            driver: "gelf"
            options:
                gelf-address: "udp://graylog:12201"
                tag: "oms-events"

volumes:
    mongodb:
        driver: "local"
    elasticsearch:
        driver: "local"

(the ./docker/mongo and ./oms-events folder contains Dockerfiles to build the image from).

  • Debugging staging docker compose server with pycharm
  • GitLab-CI Multi Runner php composer cache
  • Porting issue with Docker
  • docker: Says connection refused when attempting to connect to a published port
  • Effect of a driver in the host OS to a Docker process
  • flocker plugin not found, error response from daemon
  • The thing is, if I run it it will throw an error:

    ERROR: for omsevents  Cannot start service omsevents: Failed to initialize logging driver: gelf: cannot connect to GELF endpoint: graylog:12201 dial udp: lookup graylog: no such host
    ERROR: Encountered errors while bringing up the project.
    

    If I remove the logging block from the oms-events config, this will work, but this won’t forward the logs to GELF.

    My guess is that is happening because Graylog and Elasticsearch aren’t set up when the oms-events service is starting, that’s why it cannot connect to it. But I’m not sure about it.

    How can I fix this?

  • Can I dockerize Activex exe which has GUI?
  • Use github private repo deploy key inside build stage in docker for npm install
  • Specify runtime for self container .Net Core app in Docker
  • Making a REST Call to Endpoint in Dockers
  • Deploying an app for every user
  • Synchronizing multiple servers and local machines with the same data / source code
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.