3

My use case:

I use a containerized octoprint instance to drive a 3dprinter. The problem I'm running into is that if the printer(usb) isn't connected during the boot process of the container, then it doesn't boot at all. Docker compose can't find the usb device when it's not connected which causes the container to not boot.

The problem is that the printer is physically turned off when it's not actively printing and turning the printer on every time when the container needs a reboot is not a feasible solution. Is there a way (within docker compose land) to boot the container when a device is not available and then link it once it comes available? OR check if the device is present and if it's not then just boot without it. The host OS I'm using is raspberry pi OS.

The way I have it configured right now is like this:

version: '3'
services:
  octoprint:
    container_name:octoprint
    image: "octoprint/octoprint"
    devices:
      - "/dev/ttyUSB0:/dev/ttyUSB0"
    network_mode:host
    restart: unless-stopped

I can't figure out a way to do this.

The only thing I can think of is to create a script that fires when /dev/ttyUSB0 is created and then add it to the already running container. But this seems like a worst case solution. I would like to solve this within the docker/docker compose framework.

One other "solution" is to automatically reboot the container, every time the printer gets turned on through a homeassistant integration. This is also a worst case scenario solution which I would like to avoid.

Also I'm not quite sure If I should post this on the "superuser" branch of stackexchange or the unix/devops branch. Please correct me if I should post this elsewhere.

BugSquanch
  • 3,053

1 Answers1

4

As a workaround you can use privileged mode and mount the whole /dev directory to your container:

privileged: true
    devices:
      - '/dev:/dev'

source

mashuptwice
  • 3,395