Change logging driver for a running container?

Hi All :slight_smile:

I am currently configuring/changing logging for my docker containers. As I already have several environments with a default logging driver json-file I wonder I it is possible to change the logging driver without container recreation? I do not see options relevant to logging in docker start, only in docker run. Is it possible? Maybe with api instead of cli?

Thanks for all help.

BR,
Rafal.

1 Like

I tried to use the api to update the container which was running and stopped with:

$ cat file.json
{“HostConfig”:{“LogConfig”:{“Type”:“journald”,“Config”:{}}}}
$ curl -X POST -H “Content-Type: application/json” --data @file.json --unix-socket /var/run/docker.sock http:/containers/123456789/update

and alternatively:

$ curl -s --unix-socket /var/run/docker.sock http:/containers/123456789/json > file2.json

modified

HostConfig.LogConfig from { “Type”: “json-file”, “Config”: {}} to { “Type”: “journald”, “Config”: {}}

and

LogPath from “/var/lib/docker/containers/123456789/123456789-json.log” to “”

and kept rest of the json as it was and then

$ curl -X POST -H “Content-Type: application/json” --data @file2.json --unix-socket /var/run/docker.sock http:/containers/123456789/update

but despite the fact that exitcode of curl is 0 and I do not get any error only

{“Warnings”:null}

from docker deamon the update is not done.
Am I missing something?

BR,
Rafal.

I would love to see an answer to this. A couple of my containers have 2GB+ logfiles, and I’m not sure how to deal with that properly using Docker.

logrotate can rotate the files as a workaround, but I’d prefer a Docker way.

@rradecki I don’t think the logging driver can be changed for a running container (although I could be wrong). Trying to modify it through the API directly, strikes me as especially “Here Be Dragons”. I’d be quite shocked if that worked…

Why not just re-run it? Containers are meant to be ephemeral and removed / new ones started constantly.

@stefanlasiewski Docker will rotate by default in json file if you set the proper --log-opts. If the containers are logging to disk, consider configuring the process to log to STDOUT/STDERR and/or you can just tail -f the logs for the ENTRYPOINT of the container after exec-ing the process you want to run (this is slightly more belabored than it looks however, see gosu as an example of issues which can come up with signal forwarding).