allfro / device-mapping-manager

58 stars 9 forks source link

Support for managing containers and devices with labels #18

Open cdalvaro opened 1 month ago

cdalvaro commented 1 month ago

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: