Reputation: 1068
I want to use a centralized log catcher like Logentries, but I don't want its agent running inside all of my containers. Thus I plan for each service to log to its container's stdout, which is then passed to Logentries via the Docker API or a logging container.
The question: How do I handle a container that needs to output two logs? How do I keep them clean and separate without introducing another logging mechanism?
The scenario: I have a PHP app, which necessitates three components: Nginx, PHP-FPM, and my code. I can put Nginx and PHP-FPM in separate Docker containers, so they'll have separate logs, so we're good there. But my PHP has to be in the same container as Nginx so that it can be served, right?
When my app needs to log something (using Monolog), I can send it to the stdout of the container (e.g., make the log file a link to /dev/stdout), but then I can't keep the logs for Nginx and my app separate.
Is there a way to do that? Or am I looking at this all wrong? Is there a better way to run Nginx + PHP in Docker?
Upvotes: 2
Views: 2398
Reputation: 1
It is definitely possible to separate your application into two containers, it's actually the recommended way to do it (Remember: one process per container).
Simply use a docker-compose.yml file like this(or manually launch them):
services:
app:
build: .
ports:
- 9000
nginx:
image: nginx
ports:
- "80:80"
volumes:
- $PWD/nginx.conf:/etc/nginx/conf.d/default.conf
And a nginx.conf file like this:
server {
listen 80;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/.+\.php(/|$) {
fastcgi_pass app:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Using this kind of configuration, you will now have 2 containers from which you can manage logs separatly using the docker logging facilities.
Upvotes: 0
Reputation: 1068
Having not found a better solution, I ended up having Laravel/Monolog log to a file in a mounted volume. The Logentries agent then collects the log from the container's host. This allows my container to remain as clean as possible in that I'm not installing Supervisor or a logging agent, and it allows whatever is running the container to access the log with minimal effort.
Logging to stdout turned out not to be an option because PHP-FPM wraps each line of output from the child process so as to make it difficult to parse, and in the case of JSON logs, entirely useless. (See https://groups.google.com/forum/#!topic/highload-php-en/VXDN8-Ox9-M)
Upvotes: 1
Reputation: 6723
Have you checked out the Logentries Docker logging integration?
Upvotes: 0