Octoprint container in Debian Windows WSL 2 and Docker Desktop

Here’s a list of steps to get octoprint to run within a container on Windows. I happen to have a windows system running next to my ender so instead of infinitely waiting for a raspberry pi I decided to run octoprint in a container within windows – if possible. Using Debian was a challenge, but I prefer it over Ubuntu, so I took the extra time to figure it out. Enjoy!

Get USB serial device into Debian

PowerShell (Admin)

PS C> winget install --interactive --exact dorssel.usbipd-win

Debian:

$ sudo apt-get install usbutils hwdata usbip

Powershell Admin:

PS C> usbipd wsl list
BUSID  VID:PID    DEVICE                                                        STATE
1-1    046d:c545  USB Input Device                                              Not attached
1-2    2357:0138  TP-Link Wireless MU-MIMO USB Adapter                          Not attached
1-4    1bcf:28c4  FHD Camera, FHD Camera Microphone                             Not attached
1-5    1a86:7523  USB-SERIAL CH340 (COM4)                                       Not attached
1-13   046d:c52b  Logitech USB Input Device, USB Input Device                   Not attached

PS C> usbipd wsl attach --busid 1-4
usbipd: info: Using default distribution 'Debian'.

PS C> usbipd wsl attach --busid 1-5
usbipd: info: Using default distribution 'Debian'.

PS C> usbipd wsl list
BUSID  VID:PID    DEVICE                                                        STATE
1-1    046d:c545  USB Input Device                                              Not attached
1-2    2357:0138  TP-Link Wireless MU-MIMO USB Adapter                          Not attached
1-4    1bcf:28c4  FHD Camera, FHD Camera Microphone                             Attached - Debian
1-5    1a86:7523  USB-SERIAL CH340 (COM4)                                       Attached - Debian
1-13   046d:c52b  Logitech USB Input Device, USB Input Device                   Not attached
1-23   0bda:9210  USB Attached SCSI (UAS) Mass Storage Device                   Not attached

Debian:

# lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 1bcf:28c4 Sunplus Innovation Technology Inc. FHD Camera Microphone
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

# python3 -m serial.tools.miniterm


--- Available ports:
---  1: /dev/ttyUSB0         'USB Serial'

docker-compose.yml

version: '2.4'

services:
  octoprint:
    image: octoprint/octoprint
    restart: unless-stopped
    ports:
      - 80:80
    devices:
    # use `python3 -m serial.tools.miniterm` , this requires pyserial
    #  - /dev/ttyACM0:/dev/ttyACM0
    #  - /dev/video0:/dev/video0
      - /dev/ttyUSB0
    volumes:
     - octoprint:/octoprint
    #environment:
    #  - ENABLE_MJPG_STREAMER=true

  ####
  # uncomment if you wish to edit the configuration files of octoprint
  # refer to docs on configuration editing for more information
  ####

  #config-editor:
  #  image: linuxserver/code-server
  #  ports:
  #    - 8443:8443
  #  depends_on:
  #    - octoprint
  #  restart: unless-stopped
  #  environment:
  #    - PUID=0
  #    - GUID=0
  #    - TZ=America/Chicago
  #  volumes:
  #    - octoprint:/octoprint

volumes:
  octoprint:

Success!

Docker volume backup and restore the easy way.

I haven’t had to move docker volumes around in a few years, but I finally had the need today. As usual, I searched for the process, knowing that most examples are… well… not very good. Well, as I almost resorted to pulling a manual job using ubuntu, I found a great write-up by Jarek Lipski on Medium. Here’s how you backup using alpine and tar. Also, make sure you “docker stop” the containers that use the volume, so you get a consistent backup.

Which containers use a volume?

docker ps -a --filter volume=[some_volume]

Backup using an alpine image with tar:

docker run --rm -v [some_volume]:/volume -v /tmp:/backup alpine tar -cjf /backup/[some_archive].tar.bz2 -C /volume ./

Restore:

docker run --rm -v [some_volume]:/volume -v /tmp:/backup alpine sh -c "rm -rf /volume/* /volume/..?* /volume/.[!.]* ; tar -C /volume/ -xjf /backup/[some_archive].tar.bz2"

Backup using loomchild/volume-backup

I love that Jarek also created an image to simplify further the process called loomchild/volume-backup. Here’s how the image works:

docker run -v [volume-name]:/volume -v [output-dir]:/backup --rm loomchild/volume-backup backup [archive-name]

Restore:

docker run -v [volume-name]:/volume -v [output-dir]:/backup --rm loomchild/volume-backup restore [archive-name]

What’s great is this method allows inline copying of a volume from one system to another using ssh. Here’s an example Jarek provides:

docker run -v some_volume:/volume --rm --log-driver none loomchild/volume-backup backup -c none - |\
     ssh user@new.machine docker run -i -v some_volume:/volume --rm loomchild/volume-backup restore -c none -