使用x2go连接远程docker容器(x-serve图形界面)

实验室是访问服务器的docker容器来做实验,但是一直都只有命令行模式,之前为了方便调试程序研究了pycharm的远程模式,但是运行一些会弹窗显示图片的程序时就会提示无法调用远程x-serve,这里我们使用x2go(NX远程桌面协议的衍生版本)将远程docker容器以图形界面的方式显示出来(方法很多并不只有x2go可以实现),再碰到弹窗如cv2.imshow()等语句就能够顺利执行。

第一步:在docker容器内安装add-apt-repository

#ubuntu16.04
sudo apt-get install software-properties-common python-software-properties

在ubuntu18.04会报错 E: Package 'python-software-properties' has no installation candidate,如果按照系统提示仅仅只安装software-properties-common可以代替python-software-properties, 后续步骤虽不会报错,但是在图形界面中无法打开终端。

#解决方案一
sudo apt --fix-broken install python-pycurl python-apt

#解决方案二
sudo apt-get install -y software-properties-common
sudo apt-get install -y python-software-properties

如果apt-get install报错找不到包 则需要换源(见附录2)(ubuntu16.04和18.04换源网址有区别 注意区分!!!)

第二步:添加PPA

sudo apt-add-repository -y ppa:x2go/stable
sudo apt-get update

第三步:安装x2go服务端

sudo apt-get install x2goserver x2goserver-xsession

第四步:配置桌面环境xfce4(后面x2go连接的时候需要选择xfce)

sudo apt-get install xfce4

第五步:本地安装x2go

windows:下载x2go软件安装

ubuntu:

sudo apt-get install software-properties-common python-software-properties
sudo apt-add-repository ppa:x2go/stable 
sudo apt-get update 
sudo apt-get install x2goclient #其实和服务端流程差不多

第六步:设置x2go 以图形界面方式访问远程docker容器(mesg问题见附录1)

实验效果:(感谢学弟做的测试)

这个是登陆之后的效果,还可以安装pycharm调试程序,同时cv2.imshow()能够完美执行。

附录:

1.解决mesg:ttyname.failed问题

vim /root/.profile
#找到.profile中的mesg n位置 替换成tty -s && mesg n

2.docker容器更换下载源(适用于ubuntu16.04/18.04解决E:unable to locate package xxx问题)

vim /etc/apt/sources.list  #打开系统文件

#文件内容替换
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse

sudo apt-get update #更新
# Ubuntu18.04默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
发布了14 篇原创文章 · 获赞 11 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/hesongzefairy/article/details/103352524