docker container mounting graphical

A, Docker pull the mirror, and create a container

1. Here I use the official centos7 mirror (mirror note that the free desktop)

# docker pull centos

2. Start to create the mirror and create a container (each about the meaning --name parameter is to start from the vessel name, call -p is easy to map inside and outside the port, a 5901 port mapping here, which is to wait for the next run vncserver needed port)

# docker run --name centos-desktop-vnc --privileged -p 5901:5901 --ulimit memlock=-1 -td centos /usr/sbin/init

Second, the system enters the container assembly operations required to install

1. Go to the container (due to our container from the name, so we can be positioned directly into the container, the container does not need to see id)

# Docker exec -it centos-desktop-vnc bash ### "centos-desktop-vnc" when the container is to create before we name

2. Install the desktop
2.1 look at what desktop can be installed

# Yum grouplist ## there will be a list, select the installation with a desktop according to their needs

Here I chose to install GNOME Desktop

# yum groupinstall GNOME Desktop

2.2 graphical interface to configure the default start

# Disconnect the default startup mode 
# unlink /etc/systemd/system/default.target  
/ # create graphical startup mode is the default startup mode 
# ln -sf /lib/systemd/system/graphical.target / etc / systemd / system / default .target   

3. Install the vnc server

 yum -y install tigervnc-server tigervnc-server-module 

Third, the configuration software

1. Copy the configuration template file to vncserver @: 1.service

 cp /lib/systemd/system/[email protected] /lib/systemd/system/vncserver@:1.service

2. modify the configuration file

vim This software may need to install it

yum install vim -y

Start editing configuration:

vim /lib/systemd/system/vncserver@:1.service

The <USER> replace our username on it, because the docker logged in as root, we <USER> to change root
changing for the better as follows:

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking

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

 

3. Set vnc password link

 vncserver # enter the password twice to complete the password settings

  

If there is view-only option, then choose n

4. Restart container and updates systemctl

exit # Exit container 
docker restart centos-desktop-vnc # reboot container 
docker exec -it centos-desktop-vnc bash # re-enter the container 
systemctl daemon-reload # update systemctl

  

If systemctl daemon-reload and systemctl start vncserver @: 1.service error occurs, you can try to restart the container, and the
/lib/systemd/system/vncserver@:1.service configuration in the Type = forking changed the Simple = Type
5. start vncserver @: 1.service service, and set the boot from Kai

systemctl start vncserver@:1.service && systemctl enable vncserver@:1.service

  

6. Check if the process is started
netstat -anp | grep 590 # netstat command If you do not enter yum install net-tools -y install 

7. Configure firewall
CentOS7 default firewall is not iptables, but firewalle,

# Add port 5901 
Firewall-cmd = --zone public --add-Port = 5901 / TCP 
# reload firewalle 
 Firewall-cmd --reload

  

Guess you like

Origin www.cnblogs.com/linuxxl/p/12029220.html