安装基本的工具
yum install epel-release
yum clean all
yum install febootstrap
离线安装febootstrap
centos7上没有febootstrap,需要从 centos上复制或者自行下载
# febootstrap下载地址链接:https://pan.baidu.com/s/1rPxp3-G1KryX9slJ9OrakA 提取码:ih72
rpm -Uvh *.rpm --nodeps --force
制作镜像(在物理机上执行)
# 1.创建安装文件夹
mkdir /home/centos7
# 2.执行指令
febootstrap -i bash -i wget -i yum -i iputils -i iproute -i man -i vim -i openssh-server -i openssh-clients -i tar -i p7zip -i net-tools -i "GNOME Desktop" -i tigervnc-server -i tigervnc-server-module -i gnome-classic-session -i gnome-terminal -i nautilus-open-terminal -i control-center -i liberation-mono-fonts -i bzip2 centos7.6 /home/centos7 http://mirrors.163.com/centos/7.6.1810/os/x86_64/
#(-i 安装package, centos7 操作系统版本,/home/centos7安装目录,最后是源地址)
### 3.执行结果如下
Complete!
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
load镜像
tar -c .|docker import - centos7:v1
/home/edu/novnc/novnc/noVNC-1.0.0/utils/websockify/run --web /home/edu/novnc/novnc/noVNC-1.0.0 --target-config /home/edu/novnc/novnc/vnc_tokens 6080
制作ssh可登陆
FROM centos7.6:v1
MAINTAINER liuyunsheng
WORKDIR /root
USER 0
RUN echo "root:111111" | chpasswd \
&& echo "root ALL=(ALL) ALL" >> /etc/sudoers
EXPOSE 22
CMD ["/usr/sbin/init"]
特权模式启动容器
docker run --privileged -ti centos7:ssh /usr/sbin/init
制作vnc服务
#复制vncserver@:1.service即可
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
vncserver@:1.service内容
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
vncserver@:1.service内容修改为root
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
使服务生效
vncpasswd #为root用户设置密码,为123456
systemctl daemon-reload
systemctl start vncserver@:1.service
systemctl enable vncserver@:1.service
systemctl status vncserver@:1.service