Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access php error logs in Docker

Tags:

php

docker

How can I access the php error logs for my container?

For some reason I'm really struggling to find out how to do this after a long time of searching various articles.

I'm using a simple php7 apache container which looks like: FROM php:7-apache

RUN apt-get update -y && apt-get install -y \
        libpng12-dev \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        curl \
        libcurl4-openssl-dev \
        libxpm-dev \
        libvpx-dev \
    && docker-php-ext-configure gd \
    --with-freetype-dir=/usr/lib/x86_64-linux-gnu/ \
    --with-jpeg-dir=/usr/lib/x86_64-linux-gnu/ \
    --with-xpm-dir=/usr/lib/x86_64-linux-gnu/ \
    --with-vpx-dir=/usr/lib/x86_64-linux-gnu/ \
    && docker-php-ext-install \
        pdo \
        pdo_mysql \
        gd \
        curl \
    && a2enmod rewrite \
    && service apache2 restart

Ideally I just need to view the contents of the error log or get a new custom log set locally on my machine so I easily see potential issues with my site build.

Any pointers appreciated. I found the docker documentation very confusing on the topic of logs...

like image 776
Doidgey Avatar asked Aug 23 '17 12:08

Doidgey


People also ask

Can I access the logs of the docker container?

The docker logs command shows information logged by a running container. The docker service logs command shows information logged by all containers participating in a service. The information that is logged and the format of the log depends almost entirely on the container's endpoint command.

Where are PHP errors logged?

The location of the error log file itself can be set manually in the php. ini file. On a Windows server, in IIS, it may be something like "'error_log = C:\log_files\php_errors. log'" in Linux it may be a value of "'/var/log/php_errors.

How do I view desktop logs in docker?

You can also find the logs for the internal components included in Docker Desktop at $HOME/. docker/desktop/log/ .


2 Answers

It exists the following docker command:

docker logs -f --details containerName

that will show you the mysql and php errors log files

for more check the documentation: docker logs

like image 148
Edwin Avatar answered Sep 25 '22 01:09

Edwin


By default the container doesn't seem to log PHP errors to STDOUT or STDERR. I found that when using the php.ini-development config file (see 'Configuration' in this article) it logs a lot more useful information.

To view the logs for a container, the most basic way is to do docker ps, find the container hash, and then do docker logs container_hash.

like image 20
Jimbali Avatar answered Sep 26 '22 01:09

Jimbali