How to log user ip in Docker Swarm

There is a long standing issue for this task. The logs looks like: - - [15/Mar/2018:15:32:15 +0000] “GET / HTTP/2.0” 200

One of the solutions, from the issue’s comments, is to run a service in the host mode, the swarm load balancing for this service will not work. But if there is a load balancer behind the swarm cluster, it seems not a big problem.

For example, the configuration can be like this: an external load balancer -> nginx proxy service -> backend service.

The nginx can be restarted with a such command:

docker service update --publish-rm 443:443 --publish-add "mode=host,target=443,published=443" --force yourapp_nginx

The network_mode: “host” in docker-compose file is ignored when deploying in docker swarm.

comments powered by Disqus