Reputation: 9417
Nginx Docker file is configured to send error.log to /dev/stderr.
RUN ln -sf /dev/stdout /var/log/nginx/access.log
&& ln -sf /dev/stderr /var/log/nginx/error.log
When we run docker logs --tail=10 -f nginx
it show a combination of both error log and access log. Is there a docker command so I can only see the logs of error.log or stderr?
Upvotes: 14
Views: 52435
Reputation: 899
From the Dockerfile snippet you added in your question, it looks like you are using the official NGINX image.
The NGINX image is configured to send the main NGINX access and error logs to the Docker log collector by default. This is done by linking them to stdout and stderr, which causes all messages from both logs to be stored in the file/var/lib/docker/containers/\/\-json.log on the Docker Host.
One method is to use the docker API.
You can enable the docker API and query the logs that way, in /etc/default/docker
:
DOCKEROPTS='-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock'
Then:
http://<docker host>:4243/containers/<container name>/logs?stderr=1
See:
https://www.docker.com/blog/tips-for-deploying-nginx-official-image-with-docker/
Upvotes: 0
Reputation: 436
Try this command to get only error.log:
docker logs -f nginx 1>/dev/null
And this one for access.log:
docker logs -f nginx 2>/dev/null
Upvotes: 39