1.制作kVM镜像
参考链接:http://www.troylc.cc/rancher/2017/09/03/docker-kvm-win7.html
制作好的KVM镜像:
win2008r2_x64: https://get.v3tool.com/OS/win2008r2-kvm-x64.gz.img
2.制作容器镜像

[[email protected] docker-vm]# vim Dockerfile
FROM rancher/vm-base
COPY win2008r2-kvm-x64.gz.img /base_image/win2008r2-kvm-x64.gz.img
CMD ["-m 2048m"]
[[email protected] docker-vm]# ll -sh
total 3.1G
4.0K -rw-r--r--. 1 root root  105 Sep 23 02:24 Dockerfile
3.1G -rw-r--r--. 1 root root 3.1G Sep 22 07:12 win2008r2-kvm-x64.gz.img
[[email protected] docker-vm]# docker build -t rancher/win2k8r2-kvm-docker-base .
Sending build context to Docker daemon  3.308GB
Step 1/3 : FROM rancher/vm-base
 ---> 051656d3329d
Step 2/3 : COPY win2008r2-kvm-x64.gz.img /base_image/win2008r2-kvm-x64.gz.img
 ---> 618de7c3db04
Step 3/3 : CMD ["-m 2048m"]
 ---> Running in 30acf2184949
Removing intermediate container 30acf2184949
 ---> e6b317e0384f
Successfully built e6b317e0384f
Successfully tagged rancher/win2k8r2-kvm-docker-base:latest

3.运行RancherVM

[[email protected] docker-vm]# docker run -d -v /var/run:/var/run -p 8888:80 -v /var/lib/rancher/vm:/vm rancher/ranchervm
[[email protected] docker-vm]# docker images
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
rancher/win2k8r2-kvm-docker-base   latest              e6b317e0384f        39 minutes ago      3.6GB
rancher/vm-base                    latest              051656d3329d        2 years ago         288MB
rancher/ranchervm                  latest              f3005c29aa04        2 years ago         250MB

浏览器打开http://ip:8888
点击Create Instance,会看到如下界面,设置完成之后点击Create。
======================================================================================


  • We will attempt to set the VM hostname using DHCP, but not all operating systems will honor it

  • The name of a Docker image built from rancher/osbase

  • KVM allows you to provision more memory than the host has, as long as the memory is not in use

  • KVM lets you specify a # of vCPUs larger than # of cores on the host

  • A comma-separated list of port mappings specified in docker run -p command line syntax

======================================================================================
等待10分钟左右,如果出现Console选项,点击此选项即可进入vnc界面。

ACTIONS
Stop Console

======================================================================================
4.虚拟机嵌套(在虚拟机里面运行虚拟机)

#1.检查cup是否支持虚拟化
$ egrep "(svm|vmx)" /proc/cpuinfo
$ #返回文本中有vmx,则支持虚拟化。

#2.检查是否加载KVM模块
$ lsmod | grep kvm 
kvm_intel             172032  0
kvm                   544768  1 kvm_intel
irqbypass              16384  1 kvm
 #有上面信息输出 则成功

3.检查 KVM host(母机)上是否打开了嵌套虚拟机功能
[[email protected] docker-vm]# modinfo kvm_intel | grep nested
parm:           nested:bool
[[email protected] docker-vm]# cat /sys/module/kvm_intel/parameters/nested
N
#如果显示结果不是 Y 的话需要开启 nested:
[[email protected] docker-vm]# modprobe -r kvm-intel
[[email protected] docker-vm]# modprobe kvm-intel nested=1
#或者直接修改kvm-nested.conf开启 nested:
[[email protected] docker-vm]# echo "options kvm_intel nested=1" >> /etc/modprobe.d/kvm-nested.conf
[[email protected] docker-vm]# cat /sys/module/kvm_intel/parameters/nested
Y
#再次检查输出为Y则已开启嵌套虚拟机功能
分类: Main

0 条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注