Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log container in docker swarm mode

Is there a way to log the containers which are created with the docker service create in docker swarm mode?

like image 708
sope Avatar asked Jun 21 '16 09:06

sope


People also ask

Where are docker swarm logs stored?

Docker manager nodes store the swarm state and manager logs in the /var/lib/docker/swarm/ directory. This data includes the keys used to encrypt the Raft logs.

How do I access docker Swarm?

All nodes in the swarm need to connect to the manager at the IP address. Because other nodes contact the manager node on its IP address, you should use a fixed IP address. You can run ifconfig on Linux or macOS to see a list of the available network interfaces. The tutorial uses manager1 : 192.168.


2 Answers

Finally that feature has been implemented in docker 17.03. You can get the logs of a service running on different/multiple nodes with this command:

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 logs service is now a standard feature of docker >= 17.06. https://docs.docker.com/engine/reference/commandline/service_logs/

like image 142
db80 Avatar answered Sep 18 '22 10:09

db80


The feature is not yet implemented. As @ronkot said, you have to figure out which node is running your service instance and connect directly to it.

Even if the feature will probably be implemented in the future, I strongly advice you to start to play with a Docker logging drivers in order to centralize all the logs of your cluster. Here is more information: https://docs.docker.com/engine/admin/logging/overview/

Fo example, the gelf driver is perfect if you want to use something like Logstash + Kibana :-)

like image 21
Brice Argenson Avatar answered Sep 18 '22 10:09

Brice Argenson