This project introduces how to launch a Docker container on Raspberry Pi 5 and control the AI Camera from it, with actual source code examples.
The project focuses on:
- Benefits of creating applications with Docker
- Methods to control and use cameras from Docker containers on Raspberry Pi 5
- Sample applications using AI cameras (object detection and pose estimation)
When building systems combining Raspberry Pi and cameras, implementing applications based on Docker offers multiple advantages:
1. Easy setup & high reproducibility
- Same environment can be copied to multiple units
- Operating environment remains consistent between developers and users
2. Easy application startup, shutdown, and updates
- Robust against system restarts
- Easier debugging through error isolation
docker-compose up -d # Start
docker-compose down # Stop
docker-compose up --build # Update and restart3. Easy integration with CI/CD and GitHub
- By registering Docker images in GitHub Actions or GitHub Container Registry, automatic build and deployment becomes possible with each update
- Raspberry Pi 5
- microSD card with Raspberry Pi OS (64-bit, Raspberry Pi OS Bookworm)
- Raspberry Pi AI Camera
Since Raspberry Pi OS Bullseye (November 2021), there have been specification changes:
- Traditional raspistill and raspivid are deprecated
- Migrated to new libcamera-based system
This requires several countermeasures to use cameras in Docker environments.
Share Docker Host's udev with Container
Camera access requires mounting /dev/video0 and udev. To use libcamera from Docker, configure access to the host-side camera device:
devices:
- /dev/video0:/dev/video0
volumes:
- /run/udev:/run/udev:ro/dev/video0 is the V4L2 interface used by libcamera and PiCamera2.
udev is the device management mechanism in Linux that manages the state of hardware such as cameras. Since libcamera references this information to detect cameras, Docker must also share udev information. Mount /run/udev as read-only:
volumes:
- /run/udev:/run/udev:roCamera device control (actual communication, initialization, driver management) is the host's responsibility. The camera must be properly recognized and controlled on the host side for Docker containers to use it.
Therefore, driver installation must be completed on the host side:
sudo apt update && sudo apt full-upgrade
sudo apt install imx500-all # Install driver. Restart requiredReference:Official Raspberry Pi AI Camera documentation
Launch Container in "Privileged Mode"
Docker normally restricts direct access to host hardware. To use physical devices like cameras, enable "privileged mode" (privileged: true):
privileged: trueThis allows containers to access devices like /dev/video0 and /dev/media*.
Implementation Examples Combined with DockerI created two sample applications using the AI camera, which I will describe here.
Real-Time Object Detection + Web UI (Flask)
This app displays detection results in the left view while visualizing detection results over time in the right graph.
NOTE The complete code for this application is available from Sony Semiconductor Solutions on GitHub
This application captures video from an AI camera (IMX500) connected to Raspberry Pi, performs real-time object detection, and displays it in a web browser. Through the Web UI, you can easily check AI camera video and detection results
Docker Environment SetupFROM debian:bookworm
# Install gnupg and add Raspberry Pi repository
# Add a repository to obtain packages for Raspberry Pi
RUN apt update && apt install -y --no-install-recommends gnupg && \
echo "deb http://archive.raspberrypi.org/debian/ bookworm main" > /etc/apt/sources.list.d/raspi.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 82B129927FA3303E
# Upgrade packages
RUN apt update && apt -y upgrade
# Install required packages and clean up
# Install the necessary libraries. When you install imx500-all, sample models will be automatically downloaded to the /usr/share directory.
RUN apt install -y --no-install-recommends \
python3-pip \
python3-picamera2 \
imx500-all && \
apt-get clean && \
apt-get autoremove && \
rm -rf /var/cache/apt/archives/* && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy application files
COPY app/ /app/
# Install Python dependencies
RUN pip install --break-system-packages --no-cache-dir -r requirements.txt
# Expose port 5000
EXPOSE 5000
# Run the application
CMD ["python3", "app.py"]Execution Method (Object Detection)1.Environment setup - Download repository:
git clone https://github.com/SonySemiconductorSolutions/aitrios-rpi-sandbox.git
cd aitrios-rpi-sandbox/examples/docker_webui2.Install Docker environment on Raspberry Pi5:
./install_docker3.Run Docker container:
docker-compose up --build4.Check results - Access Raspberry Pi's IP address from browser:
http://<your_rpi_ip>:5000/
or
http://raspberrypi.local:5000/Pose Estimation (Skeleton Display Only) + Web UI (Flask)
This is a Dockerized Web UI application that performs real-time pose estimation. Video can be checked from browsers, and only human skeletons are overlaid on the background, enabling privacy-protected monitoring.
✅ Privacy-conscious by detecting and displaying only metadata (skeleton information) ✅ Images for skeleton drawing can be dynamically changed (prevents unintended person capture by using pre-prepared background images)
NOTE The complete code for this application is available from Sony Semiconductor Solutions on GitHubHow to Run (Pose Estimation)
If the Docker environment construction is already done and completed in the section above, you can run the following.
cd aitrios-rpi-sandbox/examples/docker_pose_estimation
docker-compose up --buildAccess the IP address of the Raspberry Pi from your browser to check the execution results.
http://<your_rpi_ip>:5000/
or
http://raspberrypi.local:5000/ConclusionIn this project, I demonstrated how to run video processing and pose estimation applications on Docker using Raspberry Pi 5 and the AI camera. I tackled the specific challenges of accessing camera hardware from within Docker containers, particularly udev device sharing and privileged mode configuration. I hope these sample applications will help you utilize the Raspberry Pi AI Camera with Docker to develop video processing applications that consider privacy.
When in TroubleIf you encounter any issues while reading the article, please feel free to comment on this article. Also, please check the support site below. Please note that it may take some time to respond to comments
If you have any questions related to Raspberry Pi, please also check and utilize the forum below.






Comments