docker Centos 7 安装 xfce4 桌面 + x11vnc + novnc

2023-05-16

docker Centos 7 安装 xfce4 桌面 + x11vnc + novnc

    • 启动容器
    • 环境变量
    • xfce4 桌面
      • 安装、启动 Xvfb
      • 安装、启动 xfce4 桌面
    • x11vnc
      • 安装 x11vnc
      • 启动 x11vnc
    • novnc

上一篇文章介绍了 命令行版 Centos 7 虚拟机安装 xfce4 桌面 + x11vnc + novnc,本篇文章介绍 docker centos7 如何安装使用 xfce4 桌面 + x11vnc + novnc。

启动容器

docker run --name centos7 -p 5901:5901 -p 6080:6080 -i -t centos:7.9.2009

环境变量

export VNC_COL_DEPTH=24
export VNC_RESOLUTION=1280x1024
export DISPLAY=:0
export VNC_PORT=5901
export NOVNC_PORT=6080

xfce4 桌面

虚拟机有真实的显示器、键盘、鼠标,相当于一台真实的计算机,可以运行真正的 x server,但 docker 与虚拟机不同,没有这些外设,不能直接运行真实的 x server,一个替代方案是使用虚拟的 x server,比如 Xvfb,或者 tigervnc 中的 Xvnc,由于之后要使用 x11vnc,所以这是选用的是 Xvfb 作为虚拟的 x server。

安装、启动 Xvfb

# 安装 Xvfb
yum -y install Xvfb
# 启动 Xvfb(虚拟 x server)
Xvfb $DISPLAY -ac -listen tcp -screen 0 ${VNC_RESOLUTION}x${VNC_COL_DEPTH} -noreset &

安装、启动 xfce4 桌面

# 安装 xfce4 桌面
yum -y install epel-release
yum -y groupinstall "Xfce"
# 启动 xfce4 桌面
xfce4-session &

x11vnc

安装 x11vnc

yum -y install x11vnc

启动 x11vnc

  1. -forever:使用默认配置启动的话,在 vnc viewer 断开连接后,x11vnc server 后自动关闭,可添加 -forever 选项防止自动关闭
  2. -shared:同一时间默认只允许一个 vnc viewer 连接,可添加 -shared 选项以允许多个 vnc viewer 同时连接
  3. -bg:默认是前台运行,可添加 -bg 选项以后台运行
  4. -repeat:在长按某个按键时无法连输输入,可添加 -repeat 选项来修复
  5. -scale:可修改分辨率
  6. -rfbport:可修改端口
x11vnc -display $DISPLAY -rfbport $VNC_PORT -scale $VNC_RESOLUTION -repeat -shared -forever -bg

使用 vnc viewer 连接 127.0.0.1:5901

image-20221105152327555

novnc

yum -y install git python36
git clone https://github.com/novnc/noVNC.git
cd noVNC/
./utils/novnc_proxy --vnc localhost:5901

image-20221105154329640

使用浏览器访问 novnc 主页 127.0.0.1:6080/vnc.html
image-20221105154210120

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

docker Centos 7 安装 xfce4 桌面 + x11vnc + novnc 的相关文章

随机推荐