08 Docker Logs - dchantzis/sfh-docker-in-development-part-1 GitHub Wiki
Source: https://serversforhackers.com/c/div-docker-logs
We need to make a tweak so everything outputs to stdout or stdeer. If we do that successfully, we can use Docker's logging mechanism to see output form Nginx, PHP and Supervisord.
In a previous section we defined in docker/app/supervisor.conf
where the stdout and stderr will output for nginx and php:
[program:nginx]
...
stdout_logfile=/dev/stdout
stderr_logfile=/dev/stderr
...
[program:php-fpm]
...
stdout_logfile=/dev/stdout
stderr_logfile=/dev/stderr
We can see that output (for a running Container), like so:
docker run -d --rm -p 8080:80 -v %cd%/appliation:/var/www/html/public shippingdocker/app:latest
docker logs <CONTAINER_ID> -f
- -f Optional parameter to follow the log on the command line (live output on the command line).
However, we have output from supervisor but not from nginx or php.
Nginx
We can adjust the Dockerfile by symlinking the nginx error and access
logs to stdout and stderr. We will add the symlink in the Dockerfile
:
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
PHP-FPM
Then in our php-fpm.conf
file adjust the error_log to:
error_log = /proc/self/fd/2
Re-build the container and run interactively:
docker build -t shippingdocker/app:latest -f docker/app/Dockerfile docker/app
docker run -d --rm -p 8080:80 -v %cd%/application:/var/www/html/public shippingdocker/app:latest
docker logs <CONTAINER_ID> -f
Then refresh the browser to localhost:8080/index.php
and check the output on the console.