cAdvisor on Synology

Running cAdvisor in Docker on Synology was a challenge, as it often wouldn’t start despite no changes to the launch options. The issue turned out to be related to the inotify settings.

The Problem

When running the following command to start cAdvisor:

docker run --name=cadvisor \
  --volume="/:/rootfs:ro" \
  --volume="/var/run:/var/run:ro" \
  --volume="/sys:/sys:ro" \
  --volume="/var/packages/ContainerManager/var/docker/:/var/lib/docker:ro" \
  --security-opt no-new-privileges=true \
  --restart=on-failure:5 \
  google/cadvisor:latest --docker_only=true
cadvisor:
  image: gcr.io/cadvisor/cadvisor:latest
  container_name: cadvisor
  read_only: true
  security_opt:
    - no-new-privileges=true
  command:
    - "--docker_only=true"
  volumes:
    - /:/rootfs:ro
    - /var/run:/var/run:ro
    - /sys:/sys:ro
    - /var/packages/ContainerManager/var/docker/:/var/lib/docker:ro
  restart: on-failure:5

I encountered the error:

F0701 00:00:00.000000       1 cadvisor.go:156] Failed to start container manager: inotify_add_watch /sys/fs/cgroup/cpu: no space left on device

This was caused by an insufficient number of inotify watches.

The Solution

To fix this, I used the Synology Task Scheduler to set the max_user_watches value at startup:

  1. Open the Task Scheduler in Synology DSM.

  2. Create a new User-defined Script.

  3. Set the task to run at Startup.

  4. In the script field, add the following command:

    sysctl fs.inotify.max_user_watches=104857
    
  5. Save the task.

This ensures that the inotify watch limit is increased every time the Synology NAS starts up, preventing the issue with cAdvisor. This simple fix solved the problem and allowed cAdvisor to run smoothly on my Synology NAS.