If there are GUI applications that you want to run in Docker, you can use the following methods to achieve it:
Ubuntu
docker run --name car_production_line -itd --restart=always --env="DISPLAY" --env="QT_X11_NO_MITSHM=1" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" car_production_line
xhost +local:docker && docker exec -it car_production_line bash -c "command"
Windows
- Install VcXsrv
- Run VcXsrv
- install docker desktop
- run docker in powershell
docker run --name car_production_line -itd --restart=always -e DISPLAY=host.docker.internal:0 car_production_line
- run GUI application in power shell
docker exec -it car_production_line bash -c 'command'
we can create a desktop shortcut to run the GUI application directly:
- set docker to start when Windows starts
- create a .bat file with the following content:
@echo off setlocal tasklist /FI "IMAGENAME eq vcxsrv.exe" | find /I "vcxsrv.exe" >nul if errorlevel 1 ( echo Starting VcXsrv... start "" "C:\Program Files\VcXsrv\vcxsrv.exe" :0 -multiwindow -clipboard -wgl -ac timeout /t 3 >nul ) else ( echo VcXsrv is already running. ) docker ps --format "" | findstr /i "car_production_line" >nul if errorlevel 1 ( echo Starting Docker container... docker run --name car_production_line -itd --restart=always -e DISPLAY=host.docker.internal:0 car_production_line ) else ( echo Docker container already running. ) powershell -Command "docker exec -it car_production_line bash -c 'biaoding'" endlocal pause
- create a desktop shortcut to the .bat file
- double-click the shortcut to run the GUI application