物理机centos6上使用docker创建centos7容器并在容器中使用KVM搭建win10系统

主宰稳场 提交于 2020-12-19 04:45:30

环境都通过前面几篇随笔摸索中搭建好了,以下就是简单的将docker创建centos7容器并配置好win10系统的过程记录一下。

 1.创建win10容器

docker run -d --name win10 -p 5900:5900 -p 5901:5901 -p 5902:5902 -p 5903:5903 -p 5904:5904 -p 5905:5905 -v /data/zkdocker/vm:/data/zkdocker/vm --privileged=true centos:7 /usr/sbin/init

2.进入容器内部

docker exec -it win10 /bin/bash

3.进入目录/data/zkdocker/vm/shm启动脚本安装vncserver

cd /data/zkdocker/vm/shm
bash start-vnc.sh

4.vnc登陆系统,关闭锁屏

Applications --> System Tools --> Settings --> Privacy --> Screen Lock Off

5.在容器centos7上搭建网桥  

vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
NAME="eth0"
BRIDGE=br0
BOOTPROTO=dhcp
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
USERCTL=no
vi /etc/sysconfig/network-scripts/ifcfg-br0

DEVICE="br0"
TYPE="Bridge"
NOBOOT="yes"
BOOTPROTO="static"
IPADDR="172.17.0.2"
NETMASK="255.255.0.0"
GATEWAY="172.17.0.1"
DNS1="202.106.46.151"
DNS2="202.106.195.68"
DELAY="0" 
上面br0的IPADDR是eth0的ip地址
         GATEWAY是dockers容器的网关地址
以上配置好后,重启容器,配置才生效
docker restart win10
设置网桥
brctl addif br0 eth0
ifconfig eth0 0.0.0.0

6.配置kvm  

创建镜像,网络选择时输入br0

7.挂载共享目录,window访问centos上的文件  

选进入win系统设置共享文件夹shm
shm文件夹右击-->属性-->共享-->高级共享-->共享此文件夹-->权限-->删除Everyone-->添加【搜索用户名】-->检查名称-->允许完全控制-->确定
再容器centos7中执行
mkdir /mnt/shm
mount -t cifs -o username=kizzle,password=admin //172.17.0.211/shm /mnt/shm

8.设置分辨率 

centos设置分辨率
win10设置分辨率

 

 9.win7.xml

<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
  virsh edit win7
or other application using the libvirt API.
-->

<domain type='kvm'>
  <name>win7</name>
  <uuid>c6d7aede-9a45-41f3-89c0-37fbd1394110</uuid>
  <memory unit='KiB'>16777216</memory>
  <currentMemory unit='KiB'>16777216</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <hyperv>
      <relaxed state='on'/>
      <vapic state='on'/>
      <spinlocks state='on' retries='8191'/>
    </hyperv>
  </features>
  <cpu mode='custom' match='exact' check='partial'>
    <model fallback='allow'>Haswell-noTSX</model>
  </cpu>
  <clock offset='localtime'>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
    <timer name='hypervclock' present='yes'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <pm>
    <suspend-to-mem enabled='no'/>
    <suspend-to-disk enabled='no'/>
  </pm>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none' io='native'/>
      <source file='/data/zkdocker/vm/vdisk.img'/>
      <target dev='hda' bus='ide'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <target dev='hdb' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>
    <controller type='usb' index='0' model='ich9-ehci1'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci1'>
      <master startport='0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0' multifunction='on'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci2'>
      <master startport='2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci3'>
      <master startport='4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <controller type='virtio-serial' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </controller>
    <interface type='bridge'>
      <mac address='52:54:00:37:da:72'/>
      <source bridge='br0'/>
      <model type='rtl8139'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target type='isa-serial' port='0'>
        <model name='isa-serial'/>
      </target>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <channel type='spicevmc'>
      <target type='virtio' name='com.redhat.spice.0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    </channel>
    <input type='tablet' bus='usb'>
      <address type='usb' bus='0' port='1'/>
    </input>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='spice' autoport='yes'>
      <listen type='address'/>
      <image compression='off'/>
    </graphics>
    <sound model='ich6'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </sound>
    <video>
      <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='2'/>
    </redirdev>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='3'/>
    </redirdev>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </memballoon>
  </devices>
</domain>

  

 

 

 

 

  

  

  

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!