Docker log rotation, docker fails to restart

hey docker guru’s, I am new to docker and trying my hardest to learn, I have googled this issue but can not find a fix.
I am trying to add log rotation but docker engine will not restart fails every time, any help would be awesome.

OS: Ubuntu 22.04.4 server
Docker engine, followed docker docks to install for the apt install method.

sudo nano /etc/docker/daemon.json

{
    "runtimes": {
        "nvidia": {
            "args": [],
            "path": "nvidia-container-runtime"
        }
    }

    "log-driver": "json-file",
        "log-opts": {
          "max-size": "20m",
          "max-file":"5"
       }
}

Even if I just use the bellow it fails (fresh docker engine install from the docs)

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "20m",
    "max-file": "5",
    "compress": "true"
  }
}

sudo systemctl restart docker
Job for docker.service failed because the control process exited with error code.
See “systemctl status docker.service” and “journalctl -xeu docker.service” for details.
journalctl -xeu docker.service

Sep 07 08:53:36 exorde systemd[1]: Failed to start Docker Application Container Engine.
░░ Subject: A start job for unit docker.service has failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A start job for unit docker.service has finished with a failure.
░░
░░ The job identifier is 19533 and the job result is failed.

any ideas and help would be awesome.

In the first json you had a syntax error. There was no comma after the runtimes block before log-driver. Since systemd tried to restart docker multiple times, even if you fix the json, you still need to wait before you can start Docker again. Otherwise it will say it restarted too quickly too many times. I don’t see that in your logs, but your first json was definitely syntactically wrong, while the second looks right.

1 Like

will give it a try thankyou for spotting that mistake.

In the second block it still errors out even when waiting 5 or 10 mins before restarting for some reason, I have wiped and reinstalled OS and docker engine multiple times and still getting that error

for anyone having same errors:

{
    "runtimes": {
        "nvidia": {
            "args": [],
            "path": "nvidia-container-runtime"
        }
    },
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "25m",
        "max-file": "5",
        "compress": "true"
    }
}

So I assume Docker now works with the fixed json.

I formatted your code. Please, make sure you read our formatting guide so you can do it next time: How to format your forum posts