Docker 配置桌面 + VNC Server

Docker 配置桌面 + VNC Server

面向docker hub构建

1
2
3
4
5
6
7
8
docker pull sheephuan/vnc4docker:ubuntu2004-xfce4-20220531

docker run --privileged -itd -p 22001:22 -p 15901:5901 --name ubuntu-xfce4 vnc-ubuntu2004:xcfe4 /usr/sbin/init

docker exec -it ubuntu-xfce4 /bin/bash

# vncserver 默认密码123456
vncserver :1 -localhost no

1654065658384.png

从零开始构建

构建Dokcer

1
2
3
4
5
6
7
docker pull ubuntu:focal-20200423

# -v hostdir:dockerdir
# 注意这样启动 无法正常使用systemctl命令
docker run -it -p 22001:22 -p 15902:5901 --name xfce4 ubuntu:focal-20200423 /bin/bash
#启动
docker exec -it huany /bin/bash

apt换源

1
2
3
4
5
# 备份
cp /etc/apt/sources.list /etc/apt/sources.list.bak
rm /etc/apt/sources.list
vim /etc/apt/sources.list

阿里云

https://developer.aliyun.com/mirror/ubuntu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

# deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

清华开源镜像站

https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 20.04 LTS
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
# 记得把https换成http
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

中科大

https://mirrors.ustc.edu.cn/help/ubuntu.html?highlight=ubuntu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 默认注释了源码仓库,如有需要可自行取消注释
deb http://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

安装桌面环境 xfce4+tigervnc

安装

1
2
3
apt update
apt install xfce4 xfce4-goodies -y
apt install tigervnc-standalone-server -y

配置vnc

设置vnc密码
1
2
3
4
# 设置vnc密码
vncpasswd
# 输入两次密码
# 第三次的view-only password 输入 n 即可
设置vnc启动桌面
1
2
# 编写xstartup文件,
vim /root/.vnc/xstartup
1
2
3
4
5
#输入以下内容
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec startxfce4
1
2
# 设置启动权限
chmod u+x /root/.vnc/xstartup
设置vnc显示选项
1
2
3
4
5
6
# in /root/.vnc/config
# vim /root/.vnc/config
geometry=1920x1080
dpi=128


启动vnc
1
2
# -localhost no表示其他IP可以访问,否则只能本地访问
vncserver -localhost no
设置 VNC 为 系统服务(我没做)
1
vim /etc/systemd/system/vncserver@.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple
User=linuxize
PAMName=login
PIDFile=/home/%u/.vnc/%H%i.pid
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver :%i -geometry 1920x1080 -alwaysshared -fg
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

保存此文件

1
2
3
4
5
6
# 配置文件生效
systemctl daemon-reload
# 设为开机启动
systemctl enable vncserver@1.service
systemctl start vncserver@1.service
systemctl status vncserver@1.service

打包镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
docker commit xfce4 vnc-ubuntu2004:xcfe4

# 容器长传
docker tag vnc-ubuntu2004:xcfe4 sheephuan/vnc4docker:ubuntu2004-xfce4-20220531
docker login
docker push sheephuan/vnc4docker:ubuntu2004-xfce4-20220531

docker save -o vnc-ubuntu2004-xcfe4.tar vnc-ubuntu2004:xcfe4



# 在新服务载入
docker load --input vnc-ubuntu2004-xcfe4.tar

考虑学习写一个Dockerfile

问题

System has not been booted with systemd as init system (PID 1). Can’t operate.

1
docker run --privileged -itd -p 22004:22  -p 15904:5901 --name txfce4 vnc-ubuntu2004:xcfe4 /usr/sbin/init

Failed to exec default Terminal Emulator

1653997211716.png

https://blog.csdn.net/weixin_42912498/article/details/107162983

Docker 配置桌面 + VNC Server

https://blog.yuanhuan.site/posts/8ab24eb0/

Author

Huan Yang

Posted on

2022-06-01

Updated on

2023-10-16

Licensed under

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×