dockerでKVM (ennweb/kvm)

* [dockerでKVM動かし、Proxmox4を動かす (ianblenke/kvm) - Qiita](http://qiita.com/tukiyo3/items/caa5d16060a614c4f1b3)よりもイメージサイズが小さい。
    * 展開時 251.7 MB
    * ubuntu 16.04 ベース
    * issue上げたら対応が早かった。

## 参考

* [ennweb/docker-kvm: QEMU/KVM docker image](https://github.com/ennweb/docker-kvm)
    * [startup.sh](https://github.com/ennweb/docker-kvm/blob/master/startup.sh)
    * [docker-kvm/Dockerfile](https://github.com/ennweb/docker-kvm/blob/master/Dockerfile)
    
## win10の例

```
qemu-img create -f qcow2 20gb.qcow2 20G
```

```rb:docker-compose.yml
kvm:
  image: ennweb/kvm
  container_name: kvm
  privileged: true
  volumes:
    - .:/data/
  environment:
    - VNC=tcp
    - RAM=1024
    - SMP=1
    - IMAGE=/data/20gb.qcow2
    #- IMAGE_CREATE=1
    - ISO_DOWNLOAD=0
    - ISO=/data/Win10_1607_Japanese_x32.iso
    - ISO2=/data/virtio-win.iso
    - KEYBOARD=ja
  ports:
    - "5911:5900"
    - "127.0.0.1:2222:22"
```

* 初期値 `IMAGE_FORMAT qcow2`

CD Bootしたい場合は `- BOOT=once=d` を追加。

### virtioでwin10 32bitをインストール

* [archive-virtio](https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/)

![virtio1.png](https://qiita-image-store.s3.amazonaws.com/0/25728/681f61f2-e3d9-f35d-22da-2bf591f307e4.png)
![virtio2.png](https://qiita-image-store.s3.amazonaws.com/0/25728/e2a08bec-51e9-08b1-94e8-048ef5f89b95.png)


## 接続方法(例)

```rb
vncviewer localhost:5900
```

```rb
ssh -p 2222 localhost
```


## winxpでfddを使う例

* [Add boot, floopy, keyboard flags. by tukiyo · Pull Request #5 · ennweb/docker-kvm](https://github.com/ennweb/docker-kvm/pull/5)
* https://github.com/OpenStackCookbook/OpenStackCookbook/blob/master/virtio-win-1.1.16.vfd
* https://raw.githubusercontent.com/OpenStackCookbook/OpenStackCookbook/master/virtio-win-1.1.16.vfd

![xp.png](https://qiita-image-store.s3.amazonaws.com/0/25728/babc7c79-cbb4-bcb2-af49-8b6f9f261222.png)


```bash:
-e FLOPPY=/data/virtio-win-1.1.16.vfd \
-e BOOT=once=d \
-e KEYBOARD=ja \
-e DISK_DEVICE=ide \
```


```bash:
docker run -d \
 --privileged \
 --restart=always \
 -p 5900:5900 \
 -p 3389:3389 \
 -v `pwd`:/data/ \
 -e VNC=tcp \
 -e RAM=512 \
 -e SMP=1 \
 -e IMAGE=/data/20gb.qcow2 \
 -e ISO_DOWNLOAD=0 \
 -e ISO=/data/xp.iso \
 -e FLOPPY=/data/virtio-win-1.1.16.vfd \
 -e BOOT=once=d \
 -e KEYBOARD=ja \
 -e DISK_DEVICE=ide \
 ennweb/kvm
```

```rb:docker-compose.yml
kvm:
  image: ennweb/kvm
  container_name: kvm
  privileged: true
  volumes:
    - .:/data/
  environment:
    - VNC=tcp
    - RAM=1024
    - SMP=2
    - IMAGE=/data/20gb.qcow2
    #- IMAGE_CREATE=1
    - ISO_DOWNLOAD=0
    - ISO=/data/xp.iso
    - FLOPPY=/data/virtio-win-1.1.16.vfd
    - BOOT=once=d
    - KEYBOARD=ja
    - DISK_DEVICE=ide

  ports:
    - "5900:5900"
    - "3389:3389"
```

----

## dockerを使わない場合

```
qemu-img create -f qcow2 20gb.qcow2 20G
```

```rb
sudo kvm \
  -name xp -smp 2 -m 1000 \
  -vnc :0  \
  -vga qxl \
  -k ja \
  -cdrom xp.iso \
  -drive file="20gb.qcow2,if=virtio" \
  -fda "virtio-win-1.1.16.vfd" \
  -boot "once=d" \
  \
  -netdev type=tap,script=/etc/qemu-ifup,id=net0 \
  -device virtio-net-pci,netdev=net0 \
  -redir :3389::3389
```

* driver iso
    * https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.139-1/virtio-win.iso


### bridge

```bash:/etc/qemu/bridge.conf
allow vmbr0
```

```bash:
 -net nic -net bridge,br=vmbr0
```

## dockerをubuntuにインストール

```bash:2017-06-19
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

sudo apt install -y docker-engine
```