李端君的博客

电子,图形,编程,游戏等分享和记录

0%

容器里跑图形应用

一般一个设备只能装一个系统,一个系统上同时只能跑一个图形服务。
如果想要跑多个图形服务,可以考虑使用容器。

生成容器系统

  1. 安装 debootstrap
1
sudo apt install debootstrap fakeroot docker.io
  1. 生成容器系统
1
fakeroot debootstrap buster root https://mirrors.ustc.edu.cn/debian/
  1. 打包成容器
1
tar --xattrs -c -C root . | docker import -c 'ENTRYPOINT ["/init"]' - debian-buster

容器系统中添加图形服务

  1. 准备 debian buster 仓库源 sources.list
1
2
3
4
5
6
7
8
9
10
11
deb https://mirrors.ustc.edu.cn/debian/ buster main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ buster main contrib non-free

deb https://mirrors.ustc.edu.cn/debian/ buster-updates main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ buster-updates main contrib non-free

deb https://mirrors.ustc.edu.cn/debian/ buster-backports main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ buster-backports main contrib non-free

deb https://mirrors.ustc.edu.cn/debian-security/ buster/updates main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian-security/ buster/updates main contrib non-free
  1. 准备 init.sh 文件
1
2
3
4
5
6
7
#!/bin/bash

Xvfb :99 -ac -listen tcp -screen 0 1280x800x24 &
sleep 3
/usr/bin/fluxbox -display :99 -screen 0 &
sleep 3
x11vnc -display :99 -forever -passwd ldj
  1. 编写 Dockerfile 文件
1
2
3
4
5
6
FROM debian-buster
COPY sources.list /etc/apt/sources.list
COPY init.sh /etc/init.sh
RUN apt update; apt install -y xvfb x11vnc fluxbox firefox-esr
EXPOSE 5900
CMD ["/etc/init.sh"]
  1. 生成 docker 镜像
1
docker build -t debian-buster-firefox .

运行容器系统

1
sudo docker run -d -p 5900:5900 debian-buster-firefox:latest

打开vnc客户端,然后连接 localhost:5900 即可看到容器系统中的图形应用 firefox