Portainer log access for auto-removing failed containers: persistent logging driver or disable auto-remove?
0 reputation · 03 Jun 2020, 03:58 UTC
0 reputation · 03 Jun 2020, 03:58 UTC
Capture container logs in Portainer when a deployment fails immediately and the container is configured with --rm or a restart policy that removes it on failure.
Portainer retrieves logs through the container engine's logging driver. If a non-standard driver (e.g., fluentd, gelf) is used, the UI may show no output. When auto-remove is enabled, the container and its default json-file logs disappear before the Logs tab can load. Real-time WebSocket streaming only works while the container exists.
Two documented workarounds exist: configure a persistent logging driver that writes outside the container lifecycle, or disable auto-remove so the stopped container remains inspectable. The trade-off is between preserving the original deployment semantics (auto-remove) and guaranteeing log visibility in Portainer without CLI fallback.
Which approach reliably preserves logs for Portainer inspection? Does switching to json-file or journald guarantee UI parity with docker logs? Are there driver-specific limitations in Portainer's log viewer that would still require CLI access?
35275 reputation · 03 Jun 2020, 05:05 UTC
To see logs in Portainer for containers that disappear on failure, you have two reliable options:
journald. The systemd journal retains logs independently of the container lifecycle, so Portainer can display them after the container is gone.--rm or the rm flag on a restart policy) and stay with the default json-file driver. The stopped container and its json-file log files remain on the host, giving Portainer full UI access.Switching to json-file while keeping auto‑remove does not work – the log files are deleted together with the container. Other drivers (fluentd, gelf, syslog, splunk, awslogs, …) forward logs outside Docker; Portainer’s UI cannot read them, so you would still need the CLI or an external log system.
docker logs./etc/systemd/journald.conf (e.g., MaxRetentionSec, MaxFileSec). Verify the journal keeps logs long enough for your debugging window.Exited state; its log file at /var/lib/docker/containers/<id>/<id>-json.log remains readable.docker logs.docker container prune or a scheduled job.--log-opt max-size=10m --log-opt max-file=3) to avoid filling the host disk.docker logs (including historical logs).docker inspect <container> --format '{{.HostConfig.LogConfig.Type}}'json-file with --rm, deploy a test container without --rm, let it fail, then open Portainer → Logs. Logs should appear. Clean up with docker container prune.--log-driver=journald --rm. After failure, check Portainer Logs and also run journalctl -u docker CONTAINER_ID=<id> to confirm parity.journalctl --disk-usage and inspect /etc/systemd/journald.conf for MaxRetentionSec/MaxFileSec.Do you need to preserve the auto‑remove semantics (i.e., the container must disappear automatically after failure)? If yes, use journald. If you can tolerate stopped containers lingering until a cleanup job runs, disabling auto‑remove with json-file is simpler and avoids journald configuration concerns.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.