Device name with ":"

Hello.

My issue is the following: I want to give to my container full access to a specific device (an FPGA card). So my plan is to use the --device option. This device option’s syntax is the following:
docker run --device=Host Device:Container Device Mapping:Permissions

My problem is the name of my device contains “:” characters like in /dev/mydevice/FAB,yp-troll.0004:00:00.1.0. And so when using this name, docker is lost:
docker: bad mode specified: 00.1.0.

Needless to say I cannot change the name of my device (or use a symbolic link with a simplest name), because this exact name is used by several tools.

How could I use such device name without docker interpreting the “:” in the name ?
(I did try ', ", \, etc)

Thanks in advance…

1 Like

FYI, I did have the same issue when trying to mount into my container any directory (like /sys/devices/pci0004:00) containing colons in its name. I see in forums that I’m not the only one facing issue with docker when you want to work with file names containing colons. And I did not find any form of escaping for those colons…
No idea really ?? Am I facing a dead end ?

I’m trying to pass a set of devices to a container which have a colon in them:

    devices:
      - /dev/disk/by-id/usb-ST2000DL_003-9VT166_152D00539000-0:0
      - /dev/disk/by-id/usb-ST2000DL_003-9VT166_152D00539000-0:1

The colon causes the device name to be truncated:

$ docker compose pull;docker compose up --detach
[+] Running 1/1
 ⠿ scrutiny Pulled                                                                                                                                     2.2s
[+] Running 0/1
 ⠿ Container scrutiny  Starting                                                                                                                        0.5s
Error response from daemon: error gathering device information while adding custom device "/dev/disk/by-id/usb-ST2000DL_003-9VT166_152D00539000-0": no such file or directory

Is there a best practice way of escaping these characters? Forward slash, back slash, double underscores, single quotes, anything?

1 Like

First of all the devices section is a list of device mappings, not a list of devices. The way you defined it would mean that

/dev/disk/by-id/usb-ST2000DL_003-9VT166_152D00539000-0

is the source device on the host and you want to attach it to the container two times. Once as “0” and once as “1”.

This is the same as you mount files or fodlers from the host.

Second, a mapping contains colons as separators, so you can’t have it in the values. As you probably now many files under /dev/disk are actually symbolic links and /dev/ itself can contain symbolic links to disks. You can controll it with udev. So you could create an other symlink under /dev.

In this case you can simply make two sombolic links in the compose project folder pointing to the two devices and use that symlink in the compose file. These symlinks would exist after reboot

ln -s "/dev/disk/by-id/usb-ST2000DL_003-9VT166_152D00539000-0:0" "$PWD/compose-usb-0"
ln -s "/dev/disk/by-id/usb-ST2000DL_003-9VT166_152D00539000-0:1" "$PWD/dev/compose-usb-1"
      devices:
        - "$PWD/compose-usb-0:/dev/compose-usb-0"
        - "$PWD/compose-usb-0:/dev/compose-usb-0"

Note that $PWD is required since it looks like the devices section doesn’t support relative path, but $PWD depends on where you run the compose command so you can replace that variable with your actual project path if you want.

Some folders have colons in them. Some devices have colons in them.

What’s the best way to escape colons in Docker Compose, so that it may better support such devices and folders?

Here’s my situation:

$ ls -la /dev/disk/by-id
total 0
Jan 17 10:51 .
Jan 17 10:51 ..
Jan 17 10:51 ata-CT250MX500SSD4_2028E2B61977 -> ../../sda
Jan 17 10:51 ata-WDC_WD20EFAX-68B2RN1_WD-WXB2A7179H3F -> ../../sdd
Jan 17 10:51 ata-WDC_WD20EFAX-68B2RN1_WD-WXB2A7179THF -> ../../sde
Jan 17 10:51 ata-WDC_WD20EFAX-68B2RN1_WD-WXB2A71DTKN1 -> ../../sdf
Jan 17 10:51 ata-WDC_WD20EFAX-68B2RN1_WD-WXB2A71K4UC0 -> ../../sdg
Jan 17 10:51 ata-WDC_WD20EFRX-68EUZN0_WD-WCC4MCYYH9D9 -> ../../sdh
Jan 17 10:51 ata-WDC_WD20EFRX-68EUZN0_WD-WCC4MEF9H43X -> ../../sdi
Jan 17 10:51 ata-WDC_WD20EFRX-68EUZN0_WD-WCC4MKE5AN2H -> ../../sdj
Jan 17 10:51 ata-WDC_WD20EFRX-68EUZN0_WD-WCC4MLAAX66L -> ../../sdk
Jan 17 10:51 usb-ST2000DL_003-9VT166_152D00539000-0:0 -> ../../sdb
Jan 17 10:51 usb-ST2000DL_003-9VT166_152D00539000-0:1 -> ../../sdc

You can see that sdb and sdc have colons in their device id. They are two separate Seagate 3.5" HDDs - they just stupidly define themselves by manufacturer and mode number rather than manufacturer and model number and serial number, like the Western Digital examples.

Here’s why this is important:

version: '3.5'
services:
  scrutiny:
    image: ghcr.io/analogj/scrutiny:master-omnibus
    container_name: ${CONTAINER_NAME}
    hostname: ${CONTAINER_NAME}.${HOSTNAME}
    dns: ${DNS}
    cap_add:
      - SYS_RAWIO
    ports:
      - 8080:8080 # webapp
      - 8086:8086 # influxDB admin
    devices:
      - /dev/disk/by-id/ata-CT250MX500SSD4_2028E2B61977
      # - /dev/disk/by-id/usb-ST2000DL_003-9VT166_152D00539000-0:0
      # - /dev/disk/by-id/usb-ST2000DL_003-9VT166_152D00539000-0:1
      - /dev/disk/by-id/ata-WDC_WD20EFAX-68B2RN1_WD-WXB2A7179H3F
      - /dev/disk/by-id/ata-WDC_WD20EFAX-68B2RN1_WD-WXB2A7179THF
      - /dev/disk/by-id/ata-WDC_WD20EFAX-68B2RN1_WD-WXB2A71DTKN1
      - /dev/disk/by-id/ata-WDC_WD20EFAX-68B2RN1_WD-WXB2A71K4UC0
      - /dev/disk/by-id/ata-WDC_WD20EFRX-68EUZN0_WD-WCC4MCYYH9D9
      - /dev/disk/by-id/ata-WDC_WD20EFRX-68EUZN0_WD-WCC4MEF9H43X
      - /dev/disk/by-id/ata-WDC_WD20EFRX-68EUZN0_WD-WCC4MKE5AN2H
      - /dev/disk/by-id/ata-WDC_WD20EFRX-68EUZN0_WD-WCC4MLAAX66L
    volumes:
      - ${DIRECTORY_CONFIG}:/opt/scrutiny/config
      - ${DIRECTORY_DATABASE}:/opt/scrutiny/influxdb
      - /run/udev:/run/udev:ro
    restart: unless-stopped

I am unable to pass the device id with a colon in it.

I’ve looked at the values available using sudo udevadm info -a -n /dev/sdb and sudo udevadm info -a -n /dev/sdc, and I cannot find a way to reference them directly.

I could create a symbolic link, but that might not persist with disconnects. The /dev/disk/by-id value will persist between reboots and disconnects.

We’re able to escape other characters, and Docker on Windows manages the use of colons fine - can this be addressed on other platforms, perhaps with single quotes, double quotes, double understores, backslashes, or any other process?