1

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).

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?

serge1peshcoff
  • 4,342
  • 11
  • 45
  • 76
  • https://stackoverflow.com/questions/31746182/docker-compose-wait-for-container-x-before-starting-y – Matt Apr 06 '17 at 06:00
  • 1
    Actually, that's not the only issue. The logging driver is external to the container so you can't reference the internal service address. If you want to keep this all in the compose definition you might need to set a static IP on the graylog container and connect to that instead. – Matt Apr 06 '17 at 08:05
  • @Matt If I'll `expose` the port of the Graylog container and will connect the log driver to the `localhost:`, should that work? – serge1peshcoff Apr 06 '17 at 09:29
  • Yep, that should do it too. I'm vaguely remembering some NAT issues with trying to connect back to a mapped port from a container though... give it a go and see. – Matt Apr 06 '17 at 11:43

0 Answers0