四川门户网站建设,郑州市网站制作公司,阿里企业邮箱下载,如何让百度快速收录题目#xff1a;docker创建Ubuntu#xff0c;Ubuntu创建桌面环境#xff0c;本机使用VNC连接 文章目录 前言docker创建基于Ubuntu:20.04的容器使用ssh连接容器容器安装桌面环境本机电脑使用VNC连接测试用python来创建的ui能否显示坑参考 前言
为什么我想要用ubuntu的桌面环…题目docker创建UbuntuUbuntu创建桌面环境本机使用VNC连接 文章目录 前言docker创建基于Ubuntu:20.04的容器使用ssh连接容器容器安装桌面环境本机电脑使用VNC连接测试用python来创建的ui能否显示坑参考 前言
为什么我想要用ubuntu的桌面环境因为我有一些软件开发需要显示GUI就这么简单。
docker创建基于Ubuntu:20.04的容器
参考给docker中的ubuntu系统安装桌面程序我们可以创建好容器。
打开powershell或者linux终端输入以下命令创建容器 warning千万不要用主机的10000端口改为3316掉坑了 docker run -tid -p 3316:22 -p 5900:5900 -p 5901:5901 --name displaytest_container --privilegedtrue ubuntu:20.04 /bin/bash从docker for windows软件中可看到容器正在运行
使用ssh连接容器
在终端输入以下命令进入容器控制台
docker exec -it displaytest_container /bin/bash安装配置ssh的必要工具
apt updateapt install vim
apt install openssh-client
apt install openssh-server
apt install net-tools编辑sshd_config文件
vim /etc/ssh/sshd_config添加PermitRootLogin yes 给root设置密码
passwd root启动ssh
service ssh start
ps -e|grep ssh设置容器启动就开启ssh
vim /root/.bashrc
# 在.bashrc末尾添加如下代码
service ssh start用自己喜欢的ssh工具连接这里我用electerm 容器安装桌面环境
在electerm终端输入以下命令安装ubuntu桌面
apt-get update
apt install -y gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal ubuntu-desktop添加vnc4server的安装源
vim /etc/apt/sources.list添加
deb http://archive.ubuntu.com/ubuntu/ bionic universe更新源
apt update安装vncserver
apt install vnc4server先启动以下vncserver生成一些文件
vncserver初次启动需要设置密码 备份启动设置
cp ~/.vnc/xstartup ~/.vnc/xstartup.bak编辑vnc启动设置
vim ~/.vnc/xstartup替换为以下内容
#!/bin/sh# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc[ -x /etc/vnc/xstartup ] exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic
x-terminal-emulator -geometry 80x241010 -ls -title $VNCDESKTOP Desktop
x-window-manager gnome-panel
gnome-settings-daemon
metacity
nautilus 重新启动vnc
vncserver -kill :1vncserver -geometry 1920x1080 :1如果是重新启动容器后再启动vnc
第一次需要进行以下设置
vim /root/.bashrc
# 在.bashrc末尾添加如下代码
rm -rf /tmp/.X1-lock
rm -rf /tmp/.X11-unix/X1每次启动容器后都需要执行以下命令来启动桌面不可以用自动运行否则终端无法运行
vncserver -geometry 1920x1080 :1本机电脑使用VNC连接
下载vnc客户端并安装
连接可见已经连上了 测试用python来创建的ui能否显示
启动终端 安装python3-pip
apt install python3-pip安装matplotlib
pip3 install matplotlib启动python3输入以下代码
import matplotlib.pyplot as plt
import numpy as npmat np.arange(0, 100).reshape(10, 10)
plt.matshow(mat)
plt.show()坑
主机的端口被占用导致映射出的端口无法进行ssh连接windows用以下方法检测是否被占用端口占用问题10000端口
参考
通过VNC搭建Ubuntu 18.04和20.04图形界面 Package ‘vnc4server‘ has no installation candidate_vnc4server没有可安装候选VNC远程桌面连接Ubuntu16.04及灰屏、仅桌面背景无图标问题解决方案_远程ubuntu背景给docker中的ubuntu系统安装桌面程序