Skip to content

Instantly share code, notes, and snippets.

@diyism
Last active May 24, 2025 14:41
Show Gist options
  • Save diyism/8f0d4b1cdfc4e9d0839927e78c90a327 to your computer and use it in GitHub Desktop.
Save diyism/8f0d4b1cdfc4e9d0839927e78c90a327 to your computer and use it in GitHub Desktop.
[Docker] Run GUI application inside Docker container
# Run Docker container with latest Ubuntu and pass DISPLAY
$ xhost +local:root #先允许Docker容器访问host的X服务器
$ docker run --net=host --env="DISPLAY" --volume="$XAUTHORITY:/root/.Xauthority:rw" -it ubuntu
# Install simple GUI applications for test
$ apt update && apt install -y x11-apps
# Run GUI application 'calculator'
$ xcalc
$ commit <con_id> ubuntu_cursor_depend
==============================dingtalk===========================================
$ export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/:/opt/apps/com.alibabainc.dingtalk/files/7.5.20-Release.40705/plugins/dtwebview/
$ wget https://dtapp-pub.dingtalk.com/dingtalk-desktop/xc_dingtalk_update/linux_deb/Release/com.alibabainc.dingtalk_7.5.20.40705_amd64.deb
$ dpkg -i com.alibabainc.dingtalk_7.5.20.40705_amd64.deb
$ ldd ./com.alibabainc.dingtalk | grep "not found" #查看所有缺失的库, 然后问gpt4o在ubuntu里怎么安装
$ apt install upower mesa-utils libgl1-mesa-dri xserver-xorg-video-intel
$ apt install libc6 libstdc++6 libgcc-s1 libglib2.0-0
$ apt install libgtkglext1
$ apt install libpulse-mainloop-glib0
$ apt install libnss3
$ apt install libxcb-shape0
$ cd /opt/apps/com.alibabainc.dingtalk/files/1.4.0-Release.20909
$ export QT_QPA_PLATFORM_PLUGIN_PATH=/opt/apps/com.alibabainc.dingtalk/files/7.5.20-Release.40705/
$ ./com.alibabainc.dingtalk //cd .. ; ./Elevator.sh
#启动后要花10分钟才真正载入完成, 否则 点击头像 切换聊天对象 几乎要花费5分钟
# install firefox
# https://support.mozilla.org/en-US/kb/install-firefox-linux#w_install-firefox-deb-package-for-debian-based-distributions
==============================cursor AI editor===========================================
# AppImage running needs "--device /dev/fuse", GPU calling needs "--device /dev/dri"
$ docker run -u root --device /dev/dri --device /dev/fuse --cap-add SYS_ADMIN --security-opt apparmor:unconfined --net=host --env="DISPLAY" -v /tmp/.X11-unix --volume="$XAUTHORITY:/home/ubuntu/.Xauthority:rw" --volume="$(pwd):/cursor:rw" -it ubuntu_cursor_depend
#在dokcer内:
$ apt install dbus-x11 libgl1 xdg-utils sudo
$ passwd ubuntu
$ service dbus start
# install googlepinin:
$ apt install --no-install-recommends fcitx-googlepinyin fcitx fcitx-config-gtk fcitx-frontend-gtk3 fcitx-ui-classic
$ echo 'run_im fcitx' > /home/ubuntu/.xinputrc
$ chown ubuntu:ubuntu /home/ubuntu/.xinputrc
# 环境变量XMODIFIERS需要设置成与host里的输入法imname不同(host里是fcitx), 否则共用的xserver会导致启动不了"fcitx -d"(报错:Another XIM daemon named fcitx is running)
$ export XMODIFIERS="@im=fcitx_docker"
$ /usr/bin/fcitx -d
# 点左fcitx-configtool(实际调用fcitx-config-gtk3)下角"+"号, 去掉"Only show current Language"(因为默认locale是C.UTF-8或en_US.UTF-8不是zh_CN.UTF-8), 再搜google
$ fcitx-configtool
$ su - ubuntu
$ export DISPLAY=:0.0
$ export $(dbus-launch)
$ cd /cursor
#setting GDK_SYNCHRONIZE, or else open file will show error: The program 'cursor' received an X Window System error'.
#need to disable mit-shm in host X server, ref: https://github.com/mviereck/x11docker/issues/326
#cat /etc/X11/xorg.conf.d/disable-MIT-SHM.conf
#Section "Extensions"
# Option "MIT-SHM" "Disable"
#EndSection
$ export GDK_SYNCHRONIZE=1
$ ./cursor-0.41.3x86_64.AppImage
# open the url from output "xdg-open: no method available for opening 'https://cursor.com/loginDeepControl?challenge=...&mode=login'
#镜像内占用超300MB: /home/ubuntu/.config/Cursor/CachedData/51c8aff7cb5a89f4a0e462fbacab938bdbfaf140
#最终 直接运行(带上了DISPLAY, GDK_SYNCHRONIZE, XMODIFIERS三个环境变量):
$ docker run -u 1000 --device /dev/dri --device /dev/fuse --cap-add SYS_ADMIN --security-opt apparmor:unconfined --net=host --env="DISPLAY" -e GDK_SYNCHRONIZE="1" -e XMODIFIERS="@im=fcitx_docker" -v /tmp/.X11-unix --volume="$XAUTHORITY:/home/ubuntu/.Xauthority:rw" --volume="$(pwd):/cursor:rw" -it ubuntu_cursor_depend
$ export $(dbus-launch); fcitx -d
$ /cursor/cursor-0.41.3x86_64.AppImage
$ echo "export \$(dbus-launch); fcitx -d ; ./cursor-0.42.0-build-241009fij7nohn5-x86_64.AppImage" > cursor.sh
$ chmod 777 cursor.sh
$ ./cursor.sh
#after reboot
$ service start docker
$ docker ps -a
$ docker start ad36
$ docker attach ad36
$ cd /cursor
$ ./cursor.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment