Connecting Docker Containers
Let’s say we have an application (
Python Django) and a webserver (
nginx) running in separate Docker containers. What we want is that both, application and webserver, send their logs to
syslog-ng that runs on the host system.
Applications that run inside a Docker conainer don’t have a direct access to the host machine by default. We need to run Docker containers with the correct configuration in order to achieve the following setup:
Docker and syslog-ng setup
On the diagram we can see that
syslog-ng sockets are mounted in Docker containers. This way, applications inside the container can be configured to write their logs to the sockets.
Here is a sample
version: '2' services: django: volumes: - /opt/logman.io/syslog-ng/var/django_log:/var/log/django_log nginx: volumes: - /opt/logman.io/syslog-ng/var/nginx_access_log:/var/log/nginx_access_log - /dev/log:/var/log/nginx_error_log
Alternatively, run docker container from command line
$ docker run -d \ --name=nginx -v /dev/log:/var/log/nginx_error_log \ -v /opt/logman.io/syslog-ng/var/nginx_access_log:/var/log/ \ nginx:latest
Add these lines in your nginx’s virtual host configuration:
access_log syslog:server=unix:/var/log/nginx_access_log; error_log syslog:server=unix:/var/log/nginx_error_log;
Make note of the socket paths from above and follow the steps in section Syslog JSON.
Docker in Cloud Container Services