Created
March 6, 2025 22:49
-
-
Save ryanlong1004/f9e781e065137c57dfa3933940a8a377 to your computer and use it in GitHub Desktop.
video_loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Docker Image for Video Playback on Raspberry Pi | |
This guide explains how to build a Docker image that runs a video in a loop on a Raspberry Pi. | |
## 1. Create a Dockerfile | |
Create a new directory for your Docker project and navigate to it. | |
```bash | |
mkdir raspberry-pi-video | |
cd raspberry-pi-video | |
``` | |
Then, create a `Dockerfile`: | |
```bash | |
nano Dockerfile | |
``` | |
Add the following content to the `Dockerfile`: | |
```Dockerfile | |
# Use a Raspberry Pi compatible base image (ARM architecture) | |
FROM arm32v7/debian:latest | |
# Install VLC or omxplayer and other dependencies | |
RUN apt-get update && apt-get install -y vlc curl && rm -rf /var/lib/apt/lists/* | |
# Copy the video file into the container | |
COPY video.mp4 /video.mp4 | |
# Set the default command to start VLC and play the video in a loop | |
CMD ["cvlc", "--no-osd", "--loop", "/video.mp4"] | |
``` | |
In this Dockerfile: | |
- We use `arm32v7/debian` as the base image because Raspberry Pi runs on ARM architecture. | |
- We install VLC (`cvlc` for command-line) along with any other necessary dependencies. | |
- The `COPY` instruction copies your video into the container (make sure you have `video.mp4` in the same directory as the Dockerfile). | |
- The `CMD` instruction runs VLC in loop mode when the container starts. | |
## 2. Build the Docker Image | |
Now that you have your `Dockerfile`, you can build the Docker image: | |
```bash | |
docker build -t raspberry-pi-video . | |
``` | |
This command will build the Docker image and tag it as `raspberry-pi-video`. | |
## 3. Run the Docker Container | |
Once the image is built, you can run the container. For this to work on your Raspberry Pi, the Docker container needs access to the display (X11 or framebuffer). You can run the container with the following command: | |
```bash | |
docker run --rm --device /dev/fb0 --privileged --env DISPLAY=:0 raspberry-pi-video | |
``` | |
This command: | |
- Allows the container to access the Raspberry Pi's framebuffer (`/dev/fb0`), which is necessary for video playback. | |
- Sets the `DISPLAY` environment variable to `:0` so that VLC can output to the connected screen. | |
- The `--privileged` flag grants additional permissions for the video playback. | |
## 4. Optional - Automate the Video Playback | |
If you want the video playback to start automatically when the Raspberry Pi boots up, you could combine this Docker setup with a `systemd` service to run the Docker container on boot. | |
Create a `systemd` service file: | |
```bash | |
sudo nano /etc/systemd/system/start_video_docker.service | |
``` | |
With the following content: | |
```ini | |
[Unit] | |
Description=Start Video in Docker on Boot | |
After=graphical.target | |
[Service] | |
ExecStart=/usr/bin/docker run --rm --device /dev/fb0 --privileged --env DISPLAY=:0 raspberry-pi-video | |
Restart=always | |
StandardOutput=null | |
StandardError=null | |
[Install] | |
WantedBy=multi-user.target | |
``` | |
Then enable and start the service: | |
```bash | |
sudo systemctl daemon-reload | |
sudo systemctl enable start_video_docker.service | |
sudo systemctl start start_video_docker.service | |
``` | |
## 5. Reboot to Test | |
Now, when your Raspberry Pi reboots, the Docker container will run, playing the video in a loop. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment