Nginx – How to monitor nginx running on a docker container with ngxtop running on the mac host

dockernginx

The official Nginx Docker image does a redirection of access.log to /dev/stdout, so that one can access the log with docker log from outside docker i.e. on the host. This is an issue because then from within the docker container I can't access access.log.

I finally resorted to install nginx on my mac and perform the following command
docker logs -f competent_edison &>> ~/Dev/monitoring/access.log

While the redirection works fine and the access.log on my mac, mirror the output of the container in realtime, ngxtop output nothing when i pass that file as parameter: ngnix -l ~/Dev/monitoring/access.log

I wonder if there is a way for ngxtop to be installed on an host, to monitor an nginx running in a container.

Please any indication would be helpful as i spend 2 days around that and can't figure out how to deal with it.

Best Answer

Sure you can. Do something like

docker logs -f <nginx-pod-name> | tee -a <nginx-pod-name>.log > /dev/null & docker run -t --rm -v <nginx-pod-name>.log:/var/log/nginx/access.log:ro mishunika/ngxtop

So to break that down: docker logs -f <nginx-pod-name> gets the log stream.

Then | tee -a <nginx-pod-name>.log > /dev/null is piping the output to tee which is appending to a file on your host (while silencing STDOUT).

Finally, you launch ngxtop and mount the log file from your host to the ngxtop container via docker run -t --rm -v <nginx-pod-name>.log:/var/log/nginx/access.log:ro mishunika/ngxtop.

This solution doesn't account for rotating the local log file but I'm assuming this is from troubleshooting purposes so that's not necessary.