0

So, as the title suggests, I have a containerized service running in docker, and I have a systemd service unit to manage said service automatically. Alongside that, I would like to have the logs for the docker container sent to the service logs. Is there any way I could have the logs provided in the docker logs SERVICE command piped to the output of the systemd service logs?

My first attempt at this was to set an ExecStartPost call to docker logs -f SERVICE, however that did not seem to work as restarting the service provided an error. I did also find this link about logging to journald, and I get the feeling this may be on the right track, but I see no explicit way provided to pipe that specifically to the systemd service in question.

Slips
  • 1

1 Answers1

0

By default, Docker uses the json-file logging driver. This writes to a flat json file on disk. You would need some external tool to parse those logs if you continued to use it which would be a complete complex mess, so you should definitely change it.

You are correct in your original assessment: Use the journald logging driver in your scenario. You would need to use the tag system to set the appropriate SYSLOG_IDENTIFIER value.

tag optional    Specify template to set CONTAINER_TAG and SYSLOG_IDENTIFIER value in journald logs. Refer to log tag option documentation to customize the log tag format.

Docker logging drivers are listed here: https://docs.docker.com/config/containers/logging/configure/#supported-logging-drivers

Rino Bino
  • 511
  • 5
  • 21