Gerico
Gerico

Reputation: 5169

Access php error logs in 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...

Upvotes: 28

Views: 67995

Answers (3)

Jimbali
Jimbali

Reputation: 2538

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.

Note: This config file will contain some unsafe values for production. You should really create your own config file with the desired logging settings.

Upvotes: 7

Edwin
Edwin

Reputation: 2278

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

Upvotes: 46

Salketer
Salketer

Reputation: 15711

All PHP output will be in the container, so you can use all the docker goodies to access the logs...

My favorite is attach as it allows you to follow the logs in real time. ( docker attach containerName )

There's also logs to see the past logs. docker logs containerName will print out all the output from the container. You might prefer adding the --tail=N flag where N is the number of lines to get.

Upvotes: 2

Related Questions