device-mapping-manager icon indicating copy to clipboard operation
device-mapping-manager copied to clipboard

Support for managing containers and devices with labels

Open cdalvaro opened this issue 1 year ago • 0 comments

I've seen that the service watches all volumes in every container.

It would be great if there was a method to filter containers and volumes with labels.

For example, you could start the device-mapping-manager service only looking for services with the label enabled by passing some environment variable like: DMM_LABEL_ENABLE=true

services:
  dmm:
    image: docker
    entrypoint: docker
    deploy:
      mode: global
    command: |
      run 
      -i
      --name device-manager 
      --restart always 
      --privileged 
      --cgroupns=host 
      --pid=host 
      --userns=host 
      -v /sys:/host/sys 
      -v /var/run/docker.sock:/var/run/docker.sock 
      ghcr.io/allfro/allfro/device-mapping-manager:latest
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      DMM_LABEL_ENABLE: 'true'

Then, for a container to be watched, you could set the following labels:

labels:
  com.allfro.device-mapping-manager.enable: 'true'
  com.allfro.device-mapping-manager.regexp: '/dev/*' # Optional. If not defined, then all volumes

That way, DMM will look for those containers with the label enabled, and will use the regexp pattern to filter only those volumes (when available).

Some services that make use of this technique are:

  • Watchtower: https://containrrr.dev/watchtower/container-selection/
  • Docker Autoheal: https://github.com/willfarrell/docker-autoheal?tab=readme-ov-file#2-use-in-your-container-image

cdalvaro avatar Oct 21 '24 16:10 cdalvaro