├── Dockerfile ├── README.md └── bin ├── kvm-start ├── net-script └── qemu-start /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:14.04 2 | RUN apt-get update -q 3 | RUN apt-get install -qy qemu-kvm socat curl dnsmasq iptables cloud-utils 4 | #RUN mkdir -p /cache 5 | #RUN curl -L https://github.com/boot2docker/boot2docker/releases/download/v0.8.0/boot2docker.iso >/cache/boot2docker.iso 6 | #RUN curl -L http://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img >/cache/trusty.img 7 | #RUN ln -s /cache/trusty.img /system.img 8 | ADD bin /usr/local/bin 9 | EXPOSE 22/tcp 4243/tcp 5900/tcp 10 | CMD kvm-start 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker-in-Docker: back with a vengeance 2 | 3 | This recipe lets you run Docker-in-Docker, with a twist. Instead of nesting 4 | containers, it runs a virtual machine within Docker, and it uses [boot2docker] 5 | to run Docker within that virtual machine. 6 | 7 | It's using KVM to start the virtual machine, so it is intended for people 8 | running Docker on bare metal. Nested virtualization might or might not work, 9 | or be just a pipe dream, I don't know. 10 | 11 | 12 | ## How to use this 13 | 14 | Clone 'dat repo. Build it. Run in `--privileged` mode on a Linux machine 15 | with KVM support. Check the IP address of the container; then you can 16 | connect using: 17 | 18 | - SSH on port 22 (user=docker, password=tcuser) 19 | - Docker on port 4243 20 | - VNC on port 5900 21 | 22 | 23 | ## Persistence 24 | 25 | If you bind-mount an empty file on /boot2docker.hdd, it will be turned into 26 | a 10 GB sparse file and formated as an ext4 filesystem and used as the 27 | data volume for boot2docker. If you want something larger/smaller, just 28 | format it yourself, and make sure that the label is boot2docker-data. 29 | 30 | 31 | [boot2docker]: https://github.com/boot2docker/boot2docker/ 32 | -------------------------------------------------------------------------------- /bin/kvm-start: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | [ -c /dev/kvm ] || mknod /dev/kvm c 10 232 3 | [ -d /dev/net ] || mkdir /dev/net 4 | [ -c /dev/net/tun ] || mknod /dev/net/tun c 10 200 5 | [ -f /etc/mtab ] || ln -s /proc/mounts /etc/mtab 6 | qemu-img create -f qcow2 -o backing_file=system.img system.qc2 7 | [ -s data.img ] || { 8 | truncate --size 10G data.img 9 | yes | mkfs -t ext4 -L boot2docker-data data.img 10 | } 11 | iptables -t nat -A POSTROUTING -s 172.18.0.0/24 -o eth0 -j MASQUERADE 12 | socat TCP-LISTEN:22,fork,reuseaddr TCP:172.18.0.2:22 & 13 | socat TCP-LISTEN:4243,fork,reuseaddr TCP:172.18.0.2:4243 & 14 | 15 | cat > cloudconfig <>/etc/default/docker 23 | - cloud-init-per once dockerrestart service docker restart 24 | EOF 25 | 26 | cloud-localds cloudconfig.img cloudconfig 27 | 28 | exec kvm -nographic -m 2048 -vnc :0 \ 29 | -drive file=system.qc2,if=virtio \ 30 | -drive file=data.img,if=virtio \ 31 | -drive file=cloudconfig.img,if=virtio \ 32 | -device virtio-net,netdev=net0 -netdev tap,id=net0,script=/usr/local/bin/net-script,downscript=no 33 | -------------------------------------------------------------------------------- /bin/net-script: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ip addr add 172.18.0.1/24 dev "$1" 3 | ip link set "$1" up 4 | dnsmasq --dhcp-range=172.18.0.2,172.18.0.2,infinite 5 | 6 | -------------------------------------------------------------------------------- /bin/qemu-start: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | socat TCP-LISTEN:22,fork,reuseaddr TCP:localhost:10022 & 3 | socat TCP-LISTEN:4243,fork,reuseaddr TCP:localhost:14243 & 4 | exec kvm -nographic -m 512 -cdrom boot2docker.iso -vnc :0 -redir 10022::22 -redir 14243::4243 5 | --------------------------------------------------------------------------------