Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to get logs in Docker Swarm?

I want to see the logs from my Docker Swarm service. Not only because I want all my logs to be collected for the usual reason, but also because I want to work out why the service is crashing with "task: non-zero exit (1)".

I see that there is work to implement docker logs in the pipeline, but there a way to access logs for production services? Or is Docker Swarm not ready for production wrt logging?

like image 236
Joe Avatar asked Nov 26 '22 22:11

Joe


2 Answers

With Docker Swarm 17.03 you can now access the logs of a multi instance service via command line.

docker service logs -f {NAME_OF_THE_SERVICE}

You can get the name of the service with:

docker service ls

Note that this is an experimental feature (not production ready) and in order to use it you must enable the experimental mode:

Update: docker service logs is now a standard feature of docker >= 17.06. https://docs.docker.com/engine/reference/commandline/service_logs/#parent-command

similar question: How to log container in docker swarm mode

like image 132
db80 Avatar answered Dec 06 '22 15:12

db80


What we've done successfully is utilize GrayLog. If you look at docker run documentation, you can specify a log-driver and log-options that allow you to send all console messages to a graylog cluster.

docker run... --log-driver=gelf --log-opt gelf-address=udp://your.gelf.ip.address:port --log-opt tag="YourIdentifier"

You can also technically configure it at the global level for the docker daemon, but I would advise against that. It won't let you add the "Tag" option, which is exceptionally useful for filtering down your results.

Docker service definitions also support log driver and log options so you can use docker service update to adjust your services without destroying them.

like image 42
Dockstar Avatar answered Dec 06 '22 16:12

Dockstar