目前用的ubuntu 22.04.4 LTS。
对于想在容器内跑gui程序,并在宿主机上使用,还是需要一些小调整的。首先,我们建一个gui的profile

incus profile create gui
incus profile edit gui

内容如下

config:
  cloud-init.vendor-data: |
    #cloud-config
    packages:
     - x11-apps
     - mesa-utils
     - pulseaudio
    runcmd:
     - 'sed -i "s/; enable-shm = yes/enable-shm = no/g" /etc/pulse/client.conf'
     - 'echo export PULSE_SERVER=unix:/tmp/.pulse-native | tee --append /home/ubuntu/.profile'
  environment.DISPLAY: :0
  raw.idmap: both 1000 1000
description: GUI LXD profile
devices:
  PASocket:
    path: /tmp/.pulse-native
    source: /run/user/1000/pulse/native
    type: disk
  X0:
    path: /tmp/.X11-unix/X0
    source: /tmp/.X11-unix/X0
    type: disk
  mygpu:
    type: gpu
name: gui

然后启动一个容器,我们就叫wechat吧

incus launch -p gui -p default images:ubuntu/22.04/cloud wechat -c security.nesting=true

如果用lxd,估计把images:ubuntu/22.04/cloud改成ubuntu:jammy就行了,因为lxd无法使用社区的镜像服务器。进入容器,开始准备安装包,先从 这里 下载最新版本deb包

incus shell wechat
apt install -y gdebi-core
gdebi /tmp/wechat-beta_1.0.0.145_amd64.fixed.deb

上面这步虽然会帮助装依赖包,但是还不够,下面继续装依赖,我从/var/log/apt/history.log翻出来的

apt install -y libnss3 libxkbcommon0 libxkbcommon-x11-0 libxcb-xkb1 libxcb-icccm4 libxcb-render0 libxcb-image0 \
libxcb-shape0 libxcb-keysyms1 libxcb-render-util0 libatomic1 libxrandr2 libxcomposite1 libxdamage1 \
libpango-1.0-0 libcairo2 libatk1.0-0 libatk-bridge2.0-0 fonts-noto –install-recommends

设置xdg环境

su – ubuntu
xdg-user-dirs-update

退出容器(因为之前是root用户),用普通用户进入

exit; exit
incus exec wechat –user 1000 — bash

如果你的DISPLAY环境变量不对,在~/.profile里加上

echo $DISPLAY (应该是:0)

现在应该可以启动微信了,执行

wechat

即可

Leave a comment