I can't get the webcam to work when running Octoprint (OctoPrint 1.10.2) under docker on an RPI 4b. I have previously had it working when using the octopi image on a RPI 2b.
`MJPG Streamer Version.: 2.0
octoprint-1 | i: Using V4L2 device.: /dev/video0
octoprint-1 | i: Desired Resolution: 640 x 480
octoprint-1 | i: Frames Per Second.: -1
octoprint-1 | i: Format............: JPEG
octoprint-1 | i: TV-Norm...........: DEFAULT
octoprint-1 | i: Could not obtain the requested pixelformat: MJPG , driver gave us: YUYV
octoprint-1 | ... will try to handle this by checking against supported formats.
octoprint-1 | ... Falling back to YUV mode (consider using -yuv option). Note that this requires much more CPU power
octoprint-1 | o: www-folder-path......: /usr/local/share/mjpg-streamer/www/
octoprint-1 | o: HTTP TCP port........: 8080
octoprint-1 | o: HTTP Listen Address..: (null)
octoprint-1 | o: username:password....: disabled
octoprint-1 | o: commands.............: enabled
octoprint-1 | libv4l2: error turning on stream: Invalid argument
octoprint-1 | Unable to start capture: Invalid argument
octoprint-1 | i: Can't enable video in first time
octoprint-1 | i: cleaning up resources allocated by input thread
`
The camera is functioning fine when I use (on the host, not in docker);
services:
octoprint:
image: octoprint/octoprint
restart: unless-stopped
privileged: true
ports:
- 80:80
devices:
# use `python -m serial.tools.miniterm` to see what the name is of the printer, this requires pyserial
# - /dev/ttyACM0:/dev/ttyACM0
- /dev/video0:/dev/video0
volumes:
- octoprint:/octoprint
# uncomment the lines below to ensure camera streaming is enabled when
# you add a video device
environment:
- ENABLE_MJPG_STREAMER=true
volumes:
octoprint:
What did you already try to solve it?
Lots of combinations of CAMERA_DEV = /dev/video or /dev/vchiq
configuring in config.txt;
camera_auto_detect=0
dtoverlay=imx219
It's taken me a while to investigate but essentially I've come to the conclusion it's simply not possible. Instead, what you can do is;
use the octoprint docker minimal container for octopriint
use raspisrv in a container for the webcam streaming
if you really wanted security put nginx in front of it.
To get raspisrv working in a container, my docker file is;
FROM debian:bookworm-slim
RUN apt-get update
# Base set of utilities
RUN apt-get --assume-yes install wget unzip make gnupg2
# Add RPI specific Repos
RUN echo "deb http://archive.raspberrypi.com/debian/ bookworm main" | tee /etc/apt/sources.list.d/raspi.list
RUN wget -O - -q http://archive.raspberrypi.org/debian/raspberrypi.gpg.key | apt-key add -
RUN apt-get update
# Now raspisrv
RUN apt install -y python3
RUN wget https://github.com/signag/raspi-cam-srv/archive/refs/heads/main.zip
RUN unzip main.zip
RUN apt install -y python3-picamera2 --no-install-recommends
RUN apt install pip -y
RUN apt install python3.11-venv -y
RUN apt install -y udev
RUN mv raspi-cam-srv-main raspi-cam-srv
RUN cd raspi-cam-srv
RUN python3 -m venv --system-site-packages /raspi-cam-srv/.venv
RUN /bin/bash -c "cd raspi-cam-srv && source .venv/bin/activate && pip install Flask==3.0.0"
RUN echo "cd raspi-cam-srv" | tee /start.sh
RUN echo "if [ ! -f /raspi-cam-srv/instance/raspiCamSrv.sqlite ]; then" | tee -a /start.sh
RUN echo " source .venv/bin/activate && flask --app raspiCamSrv init-db" | tee -a /start.sh
RUN echo "fi" | tee -a /start.sh
RUN echo "source .venv/bin/activate && flask --app raspiCamSrv run --port 5000 --host=0.0.0.0" | tee -a /start.sh
RUN chmod a+x /start.sh
CMD ["/bin/bash", "-c", "/start.sh"]
and then my docker compose file is
services:
raspicam:
image: "raspicam"
restart: unless-stopped
user: root
privileged: true
ports:
- 5000:5000
devices:
- /dev/video0:/dev/video0
- /dev/vchiq
volumes:
- /run/udev:/run/udev
- /run/dbus/:/run/dbus
- /var/local/raspisrv:/raspi-cam-srv/instance # where the database file is
octoprint:
image: octoprint/octoprint:minimal
restart: unless-stopped
privileged: true
ports:
- 80:5000
devices:
# use `python -m serial.tools.miniterm` to see what the name is of the printer, this requires pyserial
- /dev/ttyACM0:/dev/ttyACM0
volumes:
- octoprint:/octoprint
# uncomment the lines below to ensure camera streaming is enabled when
# you add a video device
environment:
- ENABLE_MJPG_STREAMER=false
volumes:
octoprint:
Octoprint still complains about vcgencmd but it's working ok
Failed to deploy a stack: time="2024-09-04T17:05:04Z" level=warning msg="/data/compose/4/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion" octoprint Pulling raspicam Pulling raspicam Error pull access denied for raspicam, repository does not exist or may require 'docker login': denied: requested access to the resource is denied octoprint Error context canceled Error response from daemon: pull access denied for raspicam, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
To make the raspicam docker image you need to take all the text the block:
and put it in a file named "Dockerfile"
then run the command "$docker build . -t raspicam" - this generates the raspicam container image, which you should be able to see when you run $docker image list