M
M
MikUrrey2021-06-26 16:41:21
PHP
MikUrrey, 2021-06-26 16:41:21

How to pull PHP logs out of the container?

In php.ini, I specified where to write the logs, in the Dockerfile I create the necessary file, in docker-compose I mount the folder with it, but as a result, the log is not created and errors are not written anywhere. I suspect that by creating a file before mounting the volume, I lose it. How to do it right?

php.ini snippet:

error_reporting = E_ALL
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = On
report_memleaks = On
html_errors = Off
error_log = "/usr/local/php-logs/php-fpm.log"

Dockerfile snippet:
FROM php:8.0-fpm

RUN mkdir -p /usr/local/php-logs && \
touch /usr/local/php-logs/php-fpm.log && \
chmod 666 /usr/local/php-logs/php-fpm.log

docker-compose snippet:
version: '3'
services:
  #PHP
  php:
    build:
      context: ./image/php8.0/.
    image: analytics/php:8.0
    container_name: analytics-php8.0
    restart: unless-stopped
    tty: true
    environment:
      SERVICE_NAME: analytics
      SERVICE_TAGS: prod
    working_dir: /var/www
    volumes:
      - ./app:/var/www
      - ./logs:/usr/local/php-logs
  #Nginx Service
  webserver:
    build:
      context: ./image/nginx/.
    image: analytics/nginx
    container_name: analytics-ngnx
    restart: unless-stopped
    tty: true
    ports:
      - "${HTTP_PORT}:80"
      - "${HTTP_SECURE_PORT}:443"
    volumes:
      - ./app:/var/www
      - ./logs:/var/log/nginx

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MikUrrey, 2021-06-28
@MikUrrey

The following advice from a like-minded person from another resource helped:
Since the entire directory where the volume is connected is replaced, you need to create a file after mounting using the CMD section:

CMD touch /usr/local/php-logs/php-fpm.log && \
  chmod 666 /usr/local/php-logs/php-fpm.log && \
  php-fpm -F

(php-fpm -F is a server start command that was already in CMD).
Now everything works just fine.

D
dmitriy, 2021-06-26
@dmitriylanets

and if so
error_log = "/var/www/logs/php-fpm.log"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question