├── .gitignore ├── Makefile ├── README.md ├── scripts └── b2d-provision.sh ├── template.json ├── tests ├── boot2docker_vagrant_parallels.bats ├── bootlocal.sh └── vagrantfile.orig └── vagrantfile.tpl /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .vagrant/ 3 | packer_cache/ 4 | *.box 5 | *.iso 6 | output* 7 | **/Vagrantfile 8 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | BOOT2DOCKER_VERSION := 17.03.1-ce 2 | 3 | B2D_ISO_FILE := boot2docker.iso 4 | B2D_ISO_URL := https://github.com/boot2docker/boot2docker/releases/download/v$(BOOT2DOCKER_VERSION)/boot2docker.iso 5 | B2D_ISO_CHECKSUM := 85f1947876c0f02e4dfbab838cc18d9b 6 | 7 | default: parallels 8 | 9 | parallels: clean-parallels build-parallels test-parallels 10 | 11 | $(B2D_ISO_FILE): 12 | curl -L -o ${B2D_ISO_FILE} ${B2D_ISO_URL} 13 | 14 | $(PRL_B2D_ISO_FILE): 15 | curl -L -o ${PRL_B2D_ISO_FILE} ${PRL_B2D_ISO_URL} 16 | 17 | build-parallels: $(B2D_ISO_FILE) 18 | packer build -parallel=false -only=parallels-iso \ 19 | -var 'B2D_ISO_FILE=${B2D_ISO_FILE}' \ 20 | -var 'B2D_ISO_CHECKSUM=${B2D_ISO_CHECKSUM}' \ 21 | template.json 22 | 23 | clean-parallels: 24 | rm -f *-parallels.box $(B2D_ISO_FILE) 25 | @cd ./tests; vagrant destroy -f || : 26 | @cd ./tests; rm -f Vagrantfile 27 | 28 | test-parallels: 29 | @cd ./tests; bats --tap *.bats 30 | 31 | .PHONY: parallels clean clean-parallels build-parallels test-parallels 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # boot2docker Vagrant Box 2 | 3 | This repository contains the scripts necessary to create a 4 | [boot2docker](https://github.com/steeve/boot2docker) Vagrant box compatible with 5 | [Parallels provider](https://github.com/Parallels/vagrant-parallels). 6 | If you work solely with Docker, this box lets you keep your Vagrant workflow and 7 | work in the most minimal Docker environment possible. 8 | 9 | ## Docker installation 10 | Docker client should be installed on your Mac. It is bundled to 11 | [Docker Toolbox](https://www.docker.com/toolbox) 12 | 13 | ## Usage 14 | 15 | The box is available on [Atlas](https://atlas.hashicorp.com/parallels/boxes/boot2docker), 16 | making it very easy to use it: 17 | 18 | ```bash 19 | vagrant init parallels/boot2docker 20 | vagrant up 21 | ``` 22 | 23 | Then you need to prepare your environment for Docker client 24 | 25 | ### If TLS is enabled (by default): 26 | 27 | ```bash 28 | # Copy TLS certificates from the VM to `./tls/` directory on your Mac host: 29 | vagrant ssh -c "sudo cp -r /var/lib/boot2docker/tls `pwd`/" 30 | 31 | export DOCKER_TLS_VERIFY="1" 32 | export DOCKER_CERT_PATH="`pwd`/tls" 33 | export DOCKER_HOST="tcp://`vagrant ssh-config | sed -n "s/[ ]*HostName[ ]*//gp"`:2376" 34 | ``` 35 | 36 | ### If TLS is disabled: 37 | Use these commands to disable TLS for Docker daemon (you should do it 38 | only once, after the initial `vagrant up`): 39 | 40 | ``` 41 | vagrant ssh -c "sudo sh -c 'echo \"export DOCKER_TLS=no\" > /var/lib/boot2docker/profile'" 42 | vagrant reload 43 | ``` 44 | 45 | Now you just need to set `DOCKER_HOST` variable: 46 | ``` 47 | unset DOCKER_TLS_VERIFY 48 | export DOCKER_HOST="tcp://`vagrant ssh-config | sed -n "s/[ ]*HostName[ ]*//gp"`:2375" 49 | ``` 50 | 51 | That's it! Now your VM can be used as Docker host, check it: 52 | 53 | ```bash 54 | docker version 55 | ... 56 | ``` 57 | 58 | ## Shared Folders 59 | `/Users` path on you Mac is shared with boot2docker VM by default. It means 60 | that you can mount any directory placed in `/Users` on your Mac into the 61 | container, for example: 62 | 63 | ```bash 64 | docker run -v /Users/bob/myapp/src:/src [...] 65 | ``` 66 | 67 | If you want to mount any directory outside of `/Users`, then you should set it 68 | (or its parent dir) as a synced folder in your Vagrantfile at first: 69 | 70 | ```ruby 71 | config.vm.synced_folder "/tmp/dir_to_share", "/tmp/dir_to_share" 72 | ``` 73 | 74 | Refer to ["Synced Folders - Basic Usage"](https://docs.vagrantup.com/v2/synced-folders/basic_usage.html) 75 | to get more details about synced folders in Vagrant. 76 | 77 | ## Tips & tricks 78 | 79 | * Vagrant synced folders has been tested with : 80 | * Parallels Shared Folders : This is default sharing system for Parallels provider 81 | * [NFS](https://docs.vagrantup.com/v2/synced-folders/nfs.html) : 82 | Set `B2D_NFS_SYNC` environment variable to use NFS for sharing folders: 83 | 84 | ```bash 85 | $ export B2D_NFS_SYNC=1 86 | $ vagrant up 87 | ``` 88 | 89 | * If you want to tune contents (custom profile, install tools inside the VM), 90 | just place a `bootlocal.sh` script alongside your Vagrantfile. 91 | It will be run in the VM automatically each time after `vagrant up`. 92 | Refer to [boot2docker FAQ](https://github.com/boot2docker/boot2docker/blob/master/doc/FAQ.md) 93 | to get more details. 94 | 95 | ## Building the Box 96 | 97 | If you want to recreate the box, rather than using the binary, then 98 | you can use the scripts and Packer template within this repository to 99 | do so in seconds. 100 | 101 | To build the box, first install the following prerequisites: 102 | 103 | * [Packer](http://www.packer.io) (at least version 0.7.5) 104 | * [Parallels Desktop for Mac](http://www.parallels.com/products/desktop/) (version 10.1.2 or higher) 105 | * [Parallels Virtualization SDK for Mac](http://www.parallels.com/download/pvsdk/) 106 | * [Bats](https://github.com/sstephenson/bats) for integration tests 107 | 108 | Then run this command to build the box for Parallels provider: 109 | 110 | ``` 111 | make 112 | ``` 113 | 114 | Execute this to run integration tests: 115 | 116 | ``` 117 | make test-parallels 118 | ``` 119 | 120 | ## Authors 121 | 122 | - Author:: Mikhail Zholobov () 123 | - Author:: Damien Duportal () 124 | -------------------------------------------------------------------------------- /scripts/b2d-provision.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | set -x 5 | 6 | MOUNT_POINT=/mnt/data 7 | B2D_PERSISTENT_DIR=${MOUNT_POINT}/var/lib/boot2docker 8 | TMP_USERDATA_DIR=/tmp/userdata 9 | HDD_DEV=/dev/sda 10 | B2D_DATA_DEV="${HDD_DEV}2" 11 | 12 | # Format globally $HDD_DEV for cleaning eventually old partition table 13 | echo "== Dumping boot2docker.iso to ${HDD_DEV} :" 14 | dd if=/tmp/boot2docker-vagrant.iso of=${HDD_DEV} 15 | 16 | # Creating one partition and formating to ext4 17 | # See https://github.com/boot2docker/boot2docker/issues/531#issuecomment-61740859 18 | echo "== Creating a second partition" 19 | echo "n 20 | p 21 | 2 22 | 23 | 24 | w 25 | "| /sbin/fdisk ${HDD_DEV} 26 | echo "== Formating the partition in ext4 with the boot2docker-data label" 27 | /sbin/mkfs.ext4 -L boot2docker-data ${B2D_DATA_DEV} 28 | 29 | echo "p" | /sbin/fdisk ${HDD_DEV} 30 | 31 | # Mounting the freshly formatted volume to copy persisted content 32 | echo "== Mounting new partition to customize" 33 | mkdir -p ${MOUNT_POINT} 34 | mount ${HDD_DEV}2 ${MOUNT_POINT} 35 | 36 | echo "== Inserting vagrant key in the userdata.tar which should be deployed when boot2docker boot" 37 | mkdir -p ${B2D_PERSISTENT_DIR} ${TMP_USERDATA_DIR}/.ssh 38 | cat <${TMP_USERDATA_DIR}/.ssh/authorized_keys 39 | ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key 40 | KEY 41 | chmod 0600 ${TMP_USERDATA_DIR}/.ssh/authorized_keys 42 | 43 | echo "== Compress and copy userdata" 44 | cd ${TMP_USERDATA_DIR} 45 | tar cf ${B2D_PERSISTENT_DIR}/userdata.tar ./.ssh 46 | 47 | echo "== Customize docker daemon" 48 | cat <${B2D_PERSISTENT_DIR}/profile 49 | # Insert custom Docker daemon settings here 50 | 51 | EOF 52 | -------------------------------------------------------------------------------- /template.json: -------------------------------------------------------------------------------- 1 | { 2 | "push": { 3 | "name": "dduportal/boot2docker" 4 | }, 5 | "variables": { 6 | "B2D_ISO_FILE": "boot2docker.iso", 7 | "B2D_ISO_CHECKSUM": "7e231d3c33e08f08b604fdc9a557b64b" 8 | }, 9 | "builders": [{ 10 | "type": "parallels-iso", 11 | "iso_url": "{{user `B2D_ISO_FILE`}}", 12 | "iso_checksum_type": "md5", 13 | "iso_checksum": "{{user `B2D_ISO_CHECKSUM`}}", 14 | "boot_wait": "5s", 15 | "guest_os_type": "linux-2.6", 16 | "ssh_username": "docker", 17 | "ssh_password": "tcuser", 18 | "shutdown_command": "sudo poweroff", 19 | "parallels_tools_mode": "disable", 20 | "prlctl": [ 21 | ["set", "{{.Name}}", "--memsize", "1536"], 22 | ["set", "{{.Name}}", "--time-sync", "off"] 23 | ] 24 | }], 25 | "provisioners": [ 26 | { 27 | "type": "file", 28 | "source": "{{user `B2D_ISO_FILE`}}", 29 | "destination": "/tmp/boot2docker-vagrant.iso" 30 | }, 31 | { 32 | "type": "shell", 33 | "execute_command": "{{ .Vars }} sudo -E -S sh '{{ .Path }}'", 34 | "scripts": [ 35 | "./scripts/b2d-provision.sh" 36 | ] 37 | } 38 | ], 39 | "post-processors": [{ 40 | "type": "vagrant", 41 | "vagrantfile_template": "vagrantfile.tpl", 42 | "output": "boot2docker-{{.Provider}}.box" 43 | }] 44 | } 45 | -------------------------------------------------------------------------------- /tests/boot2docker_vagrant_parallels.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | DOCKER_TARGET_VERSION=17.03.1-ce 4 | 5 | # Assume that Vagrantfile exists and basebox is added 6 | @test "vagrant up" { 7 | run vagrant destroy -f 8 | run vagrant box remove boot2docker-parallels-test 9 | cp vagrantfile.orig Vagrantfile 10 | vagrant up --provider=parallels 11 | } 12 | 13 | @test "vagrant ssh" { 14 | vagrant ssh -c 'echo OK' 15 | } 16 | 17 | @test "Default ssh user has sudoers rights" { 18 | [ "$(vagrant ssh -c 'sudo whoami' -- -n -T)" == "root" ] 19 | } 20 | 21 | @test "Docker client exists in the remote VM" { 22 | vagrant ssh -c 'which docker' 23 | } 24 | 25 | @test "Docker is working inside the remote VM " { 26 | vagrant ssh -c 'docker ps' 27 | } 28 | 29 | @test "Docker version is ${DOCKER_TARGET_VERSION}" { 30 | DOCKER_VERSION=$(vagrant ssh -c "docker version --format '{{.Server.Version}}'" -- -n -T) 31 | [ "${DOCKER_VERSION}" == "${DOCKER_TARGET_VERSION}" ] 32 | } 33 | 34 | @test "Custom bootlocal.sh script has been run at boot" { 35 | [ $(vagrant ssh -c 'grep OK /tmp/token-boot-local | wc -l' -- -n -T) -eq 1 ] 36 | } 37 | 38 | @test "vagrant reload" { 39 | vagrant reload 40 | } 41 | 42 | @test "'/Users' and '.' synced folders are shared via prl_fs" { 43 | run vagrant ssh -c 'mount | grep prl_fs' 44 | [ "$status" -eq 0 ] 45 | [ "${#lines[@]}" -ge 2 ] 46 | run vagrant ssh -c "ls -l /vagrant/Vagrantfile" 47 | [ "$status" -eq 0 ] 48 | } 49 | 50 | @test "NFS client is running in the VM" { 51 | [ $(vagrant ssh -c 'ps aux | grep rpc.statd | wc -l' -- -n -T) -ge 1 ] 52 | } 53 | 54 | @test "Reload VM with enabled B2D_NFS_SYNC" { 55 | export B2D_NFS_SYNC=1 56 | run vagrant reload 57 | } 58 | 59 | @test "'/Users' synced folder is shared via NFS" { 60 | run vagrant ssh -c "mount | grep '/Users.*nfs'" 61 | [ "$status" -eq 0 ] 62 | [ "${#lines[@]}" -ge 1 ] 63 | unset B2D_NFS_SYNC 64 | } 65 | 66 | @test "Default synced folder can be shared via rsync" { 67 | sed 's/#SYNC_TOKEN/config.vm.synced_folder ".", "\/vagrant", type: "rsync"/g' vagrantfile.orig > Vagrantfile 68 | vagrant reload 69 | [ $( vagrant status | grep 'running' | wc -l ) -ge 1 ] 70 | vagrant ssh -c "ls -l /vagrant/Vagrantfile" 71 | } 72 | 73 | @test "vagrant halt" { 74 | vagrant halt 75 | } 76 | 77 | @test "destroy and cleanup" { 78 | vagrant destroy -f 79 | vagrant box remove boot2docker-parallels-test 80 | } 81 | -------------------------------------------------------------------------------- /tests/bootlocal.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo OK > /tmp/token-boot-local 4 | -------------------------------------------------------------------------------- /tests/vagrantfile.orig: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | 8 | config.vm.box = "boot2docker-parallels-test" 9 | config.vm.box_url = "file://../boot2docker-parallels.box" 10 | 11 | #SYNC_TOKEN 12 | 13 | end 14 | -------------------------------------------------------------------------------- /vagrantfile.tpl: -------------------------------------------------------------------------------- 1 | Vagrant.configure("2") do |config| 2 | config.ssh.shell = "sh" 3 | config.ssh.username = "docker" 4 | 5 | # Used on Vagrant >= 1.7.x to disable the ssh key regeneration 6 | config.ssh.insert_key = false 7 | 8 | # Use NFS folder sync if env variable B2D_NFS_SYNC is set 9 | if ENV['B2D_NFS_SYNC'] 10 | config.vm.synced_folder "/Users", "/Users", type: "nfs", mount_options: ["nolock", "vers=3", "udp"], id: "nfs-sync" 11 | else 12 | config.vm.synced_folder "/Users", "/Users" 13 | end 14 | 15 | # Add bootlocal support 16 | if File.file?('./bootlocal.sh') 17 | config.vm.provision "shell", path: "bootlocal.sh", run: "always" 18 | end 19 | 20 | end 21 | --------------------------------------------------------------------------------