FIXED: Docker: How to pass USB?

flatline69

Dabbler
Joined
Jan 30, 2021
Messages
29
I've been googling around and only see this in relation to virtual machines but how do I pass USB devices to containers? I have a serial port device I would normally pass in docker-compose as "devices" in compose yaml. I only see GPU as a resource in the guided compose.
 

flatline69

Dabbler
Joined
Jan 30, 2021
Messages
29
Fixed via Truecharts which allows me to expose the serial port (app zwavejs2mqtt)

edit: Was able to get my previous container working by running in host networking + privileged. Not ideal but allowed me to retain existing configuration and not have to reset my z-wave setup.
 
Last edited:

JenJen

Dabbler
Joined
Jun 30, 2021
Messages
19
Hello,

Can you tell me what do you put in the app to select an usb port please?
 

flatline69

Dabbler
Joined
Jan 30, 2021
Messages
29
Hello,

Can you tell me what do you put in the app to select an usb port please?

Here's a dump of my configuration:

Code:
root@freenas:/mnt/ZFSPOOL/home/admin# docker inspect 126768e7ab56
[
    {
        "Id": "126768e7ab5663c577ca2d288b881b22066c239432dfe34b1749a1f2f85e3073",
        "Created": "2021-07-01T03:37:17.390893773Z",
        "Path": "docker-entrypoint.sh",
        "Args": [
            "node",
            "server/bin/www"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 24789,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2021-07-01T03:37:25.902131791Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:68fde10819c7649c0909b98856a3473ea0a8775292135cbf4f23dce57681be86",
        "ResolvConfPath": "/mnt/ZFSPOOL/ix-applications/docker/containers/5752d0146eb6f5b5e8de01801e8eaa941af845c8eb248079b7dbe810da41bbd9/resolv.conf",
        "HostnamePath": "/mnt/ZFSPOOL/ix-applications/docker/containers/5752d0146eb6f5b5e8de01801e8eaa941af845c8eb248079b7dbe810da41bbd9/hostname",
        "HostsPath": "/var/lib/kubelet/pods/3bb6526b-41e6-4999-b6f0-81eb35c4e1d7/etc-hosts",
        "LogPath": "/mnt/ZFSPOOL/ix-applications/docker/containers/126768e7ab5663c577ca2d288b881b22066c239432dfe34b1749a1f2f85e3073/126768e7ab5663c577ca2d288b881b22066c239432dfe34b1749a1f2f85e3073-json.log",
        "Name": "/k8s_ix-chart_zwavejs2mqtt-ix-chart-5b5b7f857b-vgq26_ix-zwavejs2mqtt_3bb6526b-41e6-4999-b6f0-81eb35c4e1d7_6",
        "RestartCount": 0,
        "Driver": "zfs",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "unconfined",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/mnt/ZFSPOOL/docker-data/zwavejs2mqtt:/usr/src/app/store",
                "/mnt/ZFSPOOL/docker-data/docker_shared:/shared",
                "/mnt/ZFSPOOL/docker-data/docker_storage:/storage",
                "/var/lib/kubelet/pods/3bb6526b-41e6-4999-b6f0-81eb35c4e1d7/volumes/kubernetes.io~projected/kube-api-access-bznfj:/var/run/secrets/kubernetes.io/serviceaccount:ro",
                "/var/lib/kubelet/pods/3bb6526b-41e6-4999-b6f0-81eb35c4e1d7/etc-hosts:/etc/hosts",
                "/var/lib/kubelet/pods/3bb6526b-41e6-4999-b6f0-81eb35c4e1d7/containers/ix-chart/7d62f64f:/dev/termination-log"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "container:5752d0146eb6f5b5e8de01801e8eaa941af845c8eb248079b7dbe810da41bbd9",
            "PortBindings": null,
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "container:5752d0146eb6f5b5e8de01801e8eaa941af845c8eb248079b7dbe810da41bbd9",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 1000,
            "PidMode": "",
            "Privileged": true,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": [
                "seccomp=unconfined",
                "label=disable"
            ],
            "UTSMode": "host",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "nvidia",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 2,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "/kubepods/besteffort/pod3bb6526b-41e6-4999-b6f0-81eb35c4e1d7",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 100000,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": null,
            "ReadonlyPaths": null
        },
        "GraphDriver": {
            "Data": {
                "Dataset": "ZFSPOOL/ix-applications/docker/b17d658d11a0d4f620516ea93872a49e49a98e6dce0a81abab223b5ca9e8489b",
                "Mountpoint": "/mnt/ZFSPOOL/ix-applications/docker/zfs/graph/b17d658d11a0d4f620516ea93872a49e49a98e6dce0a81abab223b5ca9e8489b"
            },
            "Name": "zfs"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/mnt/ZFSPOOL/docker-data/zwavejs2mqtt",
                "Destination": "/usr/src/app/store",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/mnt/ZFSPOOL/docker-data/docker_shared",
                "Destination": "/shared",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/mnt/ZFSPOOL/docker-data/docker_storage",
                "Destination": "/storage",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/var/lib/kubelet/pods/3bb6526b-41e6-4999-b6f0-81eb35c4e1d7/volumes/kubernetes.io~projected/kube-api-access-bznfj",
                "Destination": "/var/run/secrets/kubernetes.io/serviceaccount",
                "Mode": "ro",
                "RW": false,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/var/lib/kubelet/pods/3bb6526b-41e6-4999-b6f0-81eb35c4e1d7/etc-hosts",
                "Destination": "/etc/hosts",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/var/lib/kubelet/pods/3bb6526b-41e6-4999-b6f0-81eb35c4e1d7/containers/ix-chart/7d62f64f",
                "Destination": "/dev/termination-log",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "freenas",
            "Domainname": "",
            "User": "0",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "8091/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "TZ=America/Edmonton",
                "KUBERNETES_SERVICE_PORT=443",
                "KUBERNETES_SERVICE_PORT_HTTPS=443",
                "KUBERNETES_PORT=tcp://172.17.0.1:443",
                "KUBERNETES_PORT_443_TCP=tcp://172.17.0.1:443",
                "KUBERNETES_PORT_443_TCP_PROTO=tcp",
                "KUBERNETES_PORT_443_TCP_PORT=443",
                "KUBERNETES_PORT_443_TCP_ADDR=172.17.0.1",
                "KUBERNETES_SERVICE_HOST=172.17.0.1",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NODE_VERSION=16.3.0",
                "YARN_VERSION=1.22.5",
                "ZWAVEJS_EXTERNAL_CONFIG=/usr/src/app/store/.config-db"
            ],
            "Cmd": [
                "node",
                "server/bin/www"
            ],
            "Healthcheck": {
                "Test": [
                    "NONE"
                ]
            },
            "Image": "zwavejs/zwavejs2mqtt@sha256:d20129ad1b62e0bbdeec6a3e3a9bc1dd1d1cc9c755699036d2287689535ea2ee",
            "Volumes": null,
            "WorkingDir": "/usr/src/app",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "annotation.io.kubernetes.container.hash": "1dedbd02",
                "annotation.io.kubernetes.container.restartCount": "6",
                "annotation.io.kubernetes.container.terminationMessagePath": "/dev/termination-log",
                "annotation.io.kubernetes.container.terminationMessagePolicy": "File",
                "annotation.io.kubernetes.pod.terminationGracePeriod": "30",
                "io.kubernetes.container.logpath": "/var/log/pods/ix-zwavejs2mqtt_zwavejs2mqtt-ix-chart-5b5b7f857b-vgq26_3bb6526b-41e6-4999-b6f0-81eb35c4e1d7/ix-chart/6.log",
                "io.kubernetes.container.name": "ix-chart",
                "io.kubernetes.docker.type": "container",
                "io.kubernetes.pod.name": "zwavejs2mqtt-ix-chart-5b5b7f857b-vgq26",
                "io.kubernetes.pod.namespace": "ix-zwavejs2mqtt",
                "io.kubernetes.pod.uid": "3bb6526b-41e6-4999-b6f0-81eb35c4e1d7",
                "io.kubernetes.sandbox.id": "5752d0146eb6f5b5e8de01801e8eaa941af845c8eb248079b7dbe810da41bbd9",
                "maintainer": "robertsLando",
                "org.opencontainers.image.authors": "Daniel Lando <daniel.sorridi@gmail.com>",
                "org.opencontainers.image.created": "2021-06-30T13:37:26.440Z",
                "org.opencontainers.image.description": "Zwave to Mqtt gateway and Control Panel Web UI. Built using Nodejs, and Vue/Vuetify",
                "org.opencontainers.image.documentation": "https://zwave-js.github.io/zwavejs2mqtt/#/",
                "org.opencontainers.image.licenses": "MIT",
                "org.opencontainers.image.revision": "f1671e41c13fedfb7d8b710b15b109e40fb5da31",
                "org.opencontainers.image.source": "https://github.com/zwave-js/zwavejs2mqtt",
                "org.opencontainers.image.title": "zwavejs2mqtt",
                "org.opencontainers.image.url": "https://zwave-js.github.io/zwavejs2mqtt/#/",
                "org.opencontainers.image.vendor": "zwave-js",
                "org.opencontainers.image.version": "5.2.1"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {}
        }
    }
]
 

JenJen

Dabbler
Joined
Jun 30, 2021
Messages
19
Thank you for your answer but I didn't find USB path in your configuration.

What is your "Host device path" please?
1627282713630.png


I try to find the host mounted path but it doesn't exist.
I insert a USB key and I enter the command "lsblk" but the mounted point is empty:
1627283219813.png

There is no mounted point.

JenJen
 

flatline69

Dabbler
Joined
Jan 30, 2021
Messages
29
Thank you for your answer but I didn't find USB path in your configuration.

What is your "Host device path" please?

I try to find the host mounted path but it doesn't exist.
I insert a USB key and I enter the command "lsblk" but the mounted point is empty:
View attachment 48504
There is no mounted point.

JenJen

I used Truechart pre-built package to resolve it.
 

shimian5

Dabbler
Joined
Dec 16, 2014
Messages
43
wanted to bump this topic to see if anyone else has figured out how to do this using the Docker "blue button"?
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,700
wanted to bump this topic to see if anyone else has figured out how to do this using the Docker "blue button"?
Seems to me if you want USB devices in the container, you can look at step 8 in the Docker Wizard:

1630873735471.png


It depends on what your use-case is... if you just want a quick and easy way to make it work, that checkbox would be it.

If you're more about a fully secured operational environment and/or it's not for home/personal/lab use, then look further into helm.
 

shimian5

Dabbler
Joined
Dec 16, 2014
Messages
43
That's how I did it for now. I figured for home use it's fine, but was curious if there was a more secure way to do it. All in all, it works fine though.
 
Top