Shaun
Shaun

Reputation: 490

How to view php logs information with php docker container?

I have a php-fpm docker container . Php-fpm is run inside container, can i get php-fpm's log on host machine? If i can, how to do?

Upvotes: 1

Views: 5690

Answers (2)

giorgiosironi
giorgiosironi

Reputation: 1104

The standard for Docker containers is to log to stdout/stderr. However this doesn't work well for some PHP runtimes, for example php-fpm, because of how logs get mangled in length and format.

Therefore, I switched my approach to write logs on a volume and using a sidecar container to get it into stderr and hence into Docker's log collection and/or your orchestrator.

Sample docker-compose.yml section:

cli:
    build: .
    volumes:
        - logs:/srv/annotations/var/logs
logger:
    image: busybox:1.27.2
    volumes:
        - logs:/logs
    # be careful, this will only tail alredy existing files
    command: tail -f /logs/all.json
    depends_on:
        - cli

Upvotes: 0

thaJeztah
thaJeztah

Reputation: 29047

The common approach is that applications inside a container don't log to a file, but output logs on stdout / stderr. Anything that's printed to stdout / stderr by the container's main process is collected by the built-in logging facilities of docker, and can be viewed using docker logs <container-name>.

By default, the logs are stored per-container using the json-file logging driver, and will be deleted when the container itself is deleted, but there are other logging drivers available (see Configure logging drivers) that allow you to send those logs to (e.g.) syslog, journald, gelf.

Also see

Upvotes: 5

Related Questions