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"
./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?