From 440881474998a6e70f958125f45616fbff25a517 Mon Sep 17 00:00:00 2001 From: Artur Mukhamadiev Date: Tue, 7 Oct 2025 22:16:41 +0300 Subject: [PATCH] wsl2 verified --- Dockerfile | 48 ++++++++++++++++++++++---------------------- README.md | 43 ++++++++++++++++++++------------------- build.sh | 8 -------- run.ps1 | 29 --------------------------- run.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++-------- 5 files changed, 97 insertions(+), 90 deletions(-) delete mode 100644 build.sh delete mode 100644 run.ps1 diff --git a/Dockerfile b/Dockerfile index 8089f15..e25bb52 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,25 @@ -FROM ubuntu:24.04 - -RUN apt-get update && \ - apt-get install -y \ - libglvnd0 \ - libgl1 \ - libglx0 \ - libgles2 \ - libegl1 \ - libxcb1 \ - libx11-xcb1 \ - libxkbcommon-x11-0 \ - gstreamer1.0-tools \ - gstreamer1.0-plugins-base \ - gstreamer1.0-plugins-good \ - gstreamer1.0-plugins-bad \ - gstreamer1.0-plugins-ugly \ - gstreamer1.0-libav \ - libgstreamer1.0-dev \ - libgstreamer-plugins-base1.0-dev && \ - rm -rf /var/lib/apt/lists/* - -ENV DISPLAY=:0 - +FROM ubuntu:24.04 + +RUN apt-get update && \ + apt-get install -y \ + libglvnd0 \ + libgl1 \ + libglx0 \ + libgles2 \ + libegl1 \ + libxcb1 \ + libx11-xcb1 \ + libxkbcommon-x11-0 \ + gstreamer1.0-tools \ + gstreamer1.0-plugins-base \ + gstreamer1.0-plugins-good \ + gstreamer1.0-plugins-bad \ + gstreamer1.0-plugins-ugly \ + gstreamer1.0-libav \ + libgstreamer1.0-dev \ + libgstreamer-plugins-base1.0-dev && \ + rm -rf /var/lib/apt/lists/* + +ENV DISPLAY=:0 + CMD ["bash"] \ No newline at end of file diff --git a/README.md b/README.md index e5fa79a..78bd8d9 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,22 @@ -## Base info -Here you can find simple gstreamer dockerfile and necessary scripts to work with GUI. -Scripts will not work on windows directly. It is assumed that you will be using WSL for work. - -Other way, would be using run.bat script as shown under this thread -https://stackoverflow.com/questions/73092750/how-to-show-gui-apps-from-docker-desktop-container-on-windows-11 - -## Usage - -1. Run build.sh script with container name: e.g. - - `build.sh gstreamer-base` -2. Run run.sh script with same container name: e.g. - - `run.sh gstreamer-base` - - if you're using Windows you can try (to be fair, I don't know much about powershell scripting, so this is generated by AI): - - `run.ps1 -ContainerName gstreamer-base -Build` -3. In opened bash verify that gui is opening correctly: - - `gst-launch1.0 videotestsrc ! autovideoconvert ! autovideosink` - -If video sink is not visible on the screen: -1. Make sure that wsl2 is active. -2. Make sure that WSLg is supported (should be built-in on windows 11) \ No newline at end of file +## Base info +Here you can find simple gstreamer dockerfile and necessary scripts to work with GUI. +Scripts will not work on windows directly. It is assumed that you will be using WSL for work. + +Because I wasn't able to start it up without running directly from WSL2 :D +But there are someone who was able to do this: +https://stackoverflow.com/questions/73092750/how-to-show-gui-apps-from-docker-desktop-container-on-windows-11 + +## Usage + +1. Start run.sh script with -b flag (build): + - `run.sh -b` + - _you can just use run.sh if image already built + - you can specify image name with -c flag_ +2. In opened bash verify that gui is opening correctly: + - `gst-launch1.0 videotestsrc ! autovideoconvert ! autovideosink` + +_Note: if you are using wsl2 you should see wsl=true line in terminal_ + +If video sink is not visible on the screen: +1. Make sure that wsl2 is active. +2. Make sure that WSLg is supported (should be built-in on windows 11) diff --git a/build.sh b/build.sh deleted file mode 100644 index ad0e8bf..0000000 --- a/build.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -if [[ $# -ne 1 ]]; then - echo "using: $(basename $0) " - exit 1 -fi - -docker build -t $1 . \ No newline at end of file diff --git a/run.ps1 b/run.ps1 deleted file mode 100644 index 563c2bb..0000000 --- a/run.ps1 +++ /dev/null @@ -1,29 +0,0 @@ -param( - [string]$ContainerName = "gui-app-container", - [switch]$Build -) - -if ($Build) { - Write-Host "Building Docker image: $ContainerName" -ForegroundColor Green - docker build -t $ContainerName . - - if ($LASTEXITCODE -ne 0) { - Write-Host "Build failed!" -ForegroundColor Red - exit 1 - } -} - - -$dockerCommand = @( - "run", "-it", "--rm", - "--name", $ContainerName, - "-v", "/tmp/.X11-unix:/tmp/.X11-unix", - "-v", "/run/desktop/mnt/wslg:/mnt/wslg", - "-e", "DISPLAY=$DISPLAY", - "-e", "WAYLAND_DISPLAY=wayland-0", - "-e", "XDG_RUNTIME_DIR=/mnt/wslg/runtime-dir" -) - -$dockerCommand += $ContainerName + " bash" - -docker @dockerCommand \ No newline at end of file diff --git a/run.sh b/run.sh index 395f0cc..7f12d9a 100755 --- a/run.sh +++ b/run.sh @@ -1,13 +1,56 @@ #!/bin/bash -if [[ $# -ne 1 ]]; then - echo "using: $(basename $0) " - exit 1 +usage() { + echo "usage: + $(basename $0) -c -b + default container name is gstreamer-base +" +} + +build=False +container_name="gstreamer-base" + +while getopts ":bhc:" opt; do + case $opt in + b) + build=True + ;; + h) + usage + exit 0 + ;; + c) + container_name=$OPTARG + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument (getopts)" >&2 + exit 1 + ;; + esac +done + +if [ $build = "True" ]; then + docker build . -t $container_name fi -docker run -it \ - -v /tmp/.X11-unix:/tmp/.X11-unix \ - -v $HOME/.Xauthority:/root/.Xauthority \ - -e DISPLAY=$DISPLAY \ - $1 bash +wslgPath="" +# we are running in wsl? +uname -a | grep -qi wsl && wsl=True + +if [ $wsl = "True" ]; then + echo "wsl=true" + wslgPath="-v /mnt/wslg:/mnt/wslg" +fi + +docker run --rm -it \ + -v /tmp/.X11-unix:/tmp/.X11-unix $wslgPath \ + -v $HOME/.Xauthority:/root/.Xauthority \ + -e DISPLAY \ + -e WAYLAND_DISPLAY \ + -e XDG_RUNTIME_DIR \ + $container_name bash