├── CHANGELOG.md ├── README.md ├── VERSION ├── Vagrantfile ├── docs ├── img │ ├── b2d-connection-timeout-1.png │ ├── b2d-connection-timeout-2.png │ ├── b2d-connection-timeout-3.png │ ├── network-adapter-1.png │ └── network-adapter-2.png ├── networking.md ├── synced-folders.md ├── tips.md ├── troubleshooting.md └── vm-settings.md ├── scripts ├── presetup-mac.sh ├── presetup-win.cmd ├── presetup-win.sh ├── presetup-win.vbs └── setup.sh └── vagrant.yml /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 1.7.1 (2016-08-30) 4 | 5 | - Hotfix for Vagrant v1.8.5 regression with VirtualBox shared folders on Tiny Core 6 | 7 | 8 | ## 1.7.0 (2016-08-26) 9 | 10 | - IMPORTANT: this release requires VirtualBox v5.1.x and Vagrant v1.8.5+ 11 | - Version updates 12 | - blinkreaction/boot2docker base box v1.12.1 13 | - docker cli 1.12.1 14 | - docker-compose 1.8.0 15 | - winpty 0.4.0 (Windows only) 16 | 17 | 18 | ## 1.6.2 (2016-06-27) 19 | 20 | - Hotfix: Fixed broken winpty dependency since 1.6.0 on Windows 21 | 22 | 23 | ## 1.6.1 (2016-06-03) 24 | 25 | - Hotfix for downloading new docker binary versions 26 | - Added B2D_INSTALL_MODE switch 27 | - Updated docs 28 | 29 | 30 | ## 1.6.0 (2016-06-03) 31 | 32 | - Switched to blinkreaction/boot2docker base box [v1.11.2](https://atlas.hashicorp.com/blinkreaction/boxes/boot2docker/versions/1.11.2) 33 | - boot2docker/docker 1.11.2, docker-compose 1.7.1 34 | - Set `v.memory: 1024` by default 35 | - System services 36 | - New ssh-agent service 37 | - Use the `stable` tag for vhost-proxy, dns, ssh-agent 38 | - Bind all system services to `0.0.0.0` 39 | - Run services with `--privileged --userns=host` (to give propper access to `docker.sock`) 40 | - Remove `scripts/presetup-ubuntu.sh` 41 | - Misc. imporvements in `presetup-mac.sh` and `presetup-win.sh` 42 | 43 | 44 | ## 1.5.1 (2016-04-18) 45 | 46 | - Windows fixes 47 | - Use a more complex smb_password 48 | - This addresses issues in strict password enforcement environments. 49 | - IMPORTANT (Only if you are using the `default` or `smb2` sharing type on Windows - check in `vagrant.yml`): 50 | - In an **admin cmd.exe** prompt run `net user vagrant P@ssW0rd1!` to update the existing vagrant user password. 51 | - Alternatively start fresh: `vagrant destroy -f`, then `vagrant up` 52 | - Improved winpty compatibility 53 | - IMPORTANT: Prior to updating run `rm -f /usr/local/bin/docker*` in Babun, then run the install script. 54 | - Silence docker run shell provisioning 55 | - No more red text output from `docker run` during the first VM boot 56 | - Updated VERSION file 57 | 58 | 59 | ## 1.5.0 (2016-04-14) 60 | 61 | - Switched to blinkreaction/boot2docker base box [v1.10.3](https://atlas.hashicorp.com/blinkreaction/boxes/boot2docker/versions/1.10.3) 62 | - boot2docker/docker 1.10.3, docker-compose 1.6.2 63 | - Using `upgrade` command with choco on Windows 64 | - Added winpty on Windows 65 | - This allows running interactive docker commands in Babun directly (without using `vagrant ssh -c`) 66 | - Using VirtualBox DNS proxy with the DNS Discovery service 67 | 68 | 69 | ## 1.4.0 (2016-01-20) 70 | 71 | - Version updates 72 | - Switched to blinkreaction/boot2docker base box v1.9.1 73 | - docker 1.9.1 74 | - docker-compose 1.5.2 75 | - Set NFS attribute caching of files and directories to 2 seconds 76 | - This will make sure delays in file system updates detection is within 2s. 77 | - Prevent permission (chmod) errors on SMB share 78 | - Updates in install scripts 79 | - Brew Cask is now part of Brew 80 | - Point DOCKER_HOST to 192.168.10.10 instead of localhost for better performance with Intel adapters and NAT 81 | - Suppress errors from VBoxManage on Windows 82 | - Improved messaging in setup scripts 83 | 84 | ## 1.3.1 (2015-11-16) 85 | 86 | - Remove /cygdrive prefix 87 | - /cygdrive prefix was needed for docker-compose installed via pip. The native binary does not expect this prefix. 88 | - Give all permissions on files (777) on the smb mount 89 | - Allows any script files to be executed 90 | 91 | ## 1.3.0 (2015-11-10) 92 | 93 | - Version updates 94 | - boot2docker base box v1.9.0 95 | - Docker v1.9.0 96 | - Docker Compose v1.5.0 (now installed as a binary on Windows) 97 | - Default to **nfs2** on Mac and **smb2** on Windows 98 | - rsync 99 | - Switching to vagrant-gatling-rsync for better rsync-auto performance 100 | - Auto start gatling-rsync-auto **in background** (Mac only) 101 | - Revised vboxsf, smb and rsync settings 102 | - Fixed vagrant user account expiration (smb2 option) 103 | - Added a way to define individual mounts 104 | - Added "group=system" label to dns and vhost-proxy containers 105 | - Added support for authentication against docker hub 106 | - Fixed typo: vboxfs => vboxsf 107 | 108 | ## 1.2.1 (2015-10-28) 109 | 110 | - Update path to shell scripts in README.md 111 | 112 | ## 1.2.0 (2015-10-26) 113 | 114 | - Switched to new base box version 1.8.3 115 | - Docker v1.8.3, Docker Compose v1.4.2 116 | - SFTP support (user: docker, password: tcuser or using vagrants insecure key) 117 | - Added nfs2 synced folders option with optimized NFS settings (experimental and default) 118 | - Switched to vhost-proxy [v1.1.0](https://github.com/blinkreaction/docker-nginx-proxy/releases/tag/v1.1.0) and dns-discovery [v1.0.0](https://github.com/blinkreaction/docker-dns-discovery/releases/tag/v1.0.0) container images 119 | - Moved scripts to a subfolder 120 | - Fixed Version requirements for Vagrant and Virtual Box 121 | 122 | ## 1.1.1 (2015-10-01) 123 | 124 | - Fix path to VBoxManage on Windows 125 | 126 | ## 1.1.0 (2015-09-30) 127 | 128 | - Switch to blinkreaction/boot2docker base box v1.8.2 129 | - Docker v1.8.2 130 | - Docker Compose v1.4.2 131 | - DNS resolution and service discovery 132 | - Simple DNS based service discovery using dnsmasq and docker-gen 133 | - dns service container is required and cannot be disabled 134 | - Default box IP can be configured in vagrant.yml 135 | - vhost-proxy HTTPS support 136 | - Switch to the stable branch for dsh (master) 137 | - Docs updates 138 | - DNS resolution and service discovery 139 | - Bumped required/supported VirtualBox (5.0+) and Vagrant (1.7.3+) versions 140 | - Disable default DHCP server and network interface after VirtualBox installation 141 | 142 | ## 1.0.2 (2015-09-22) 143 | 144 | - Fix docker and docker-compose install on mac 145 | - README - mention that preset scripts can be used for updates as well 146 | 147 | ## 1.0.1 (2015-09-14) 148 | 149 | - Host's home directory mapping (`~ => /.home`) to make SSH keys and other credentials and configs available to containers. 150 | 151 | ## 1.0.0 (2015-09-14) 152 | 153 | - SMB mounts on Windows 154 | - Added `smb2_auto: true/false` option to allow switching to manual provisioning of the smb user and share. 155 | - Fixed share permissions 156 | - Added Troubleshooting docs 157 | 158 | ## 1.0.0-rc2 (2015-08-18) 159 | 160 | - Upgrade to Docker 1.8.1 base box 161 | - Docker 1.8.1, Docker Compose 1.4.0 162 | - Switching to Babun shell on Windows 163 | - Now binding to the particular versions of Docker and Docker Compose on both Mac and Windows 164 | - Fully automated setup on Windows (once Babun is installed) 165 | - Minor fixes and cleanup, documentation updates 166 | 167 | ## 1.0.0-rc1 (2015-07-02) 168 | 169 | - Upgrade to Docker 1.7.0 base box 170 | - moved some provisioning scripts into the base box 171 | - vhost-proxy service is now enabled by default in vagrant.yml (`vhost_proxy: true`) 172 | - switched vhost-proxy container to a lightweight Alpine Linux base image 173 | - Added dns service to resolve *.drude to VM's primary IP address (`192.168.10.10`) 174 | - Some adjustments in the networking settings 175 | - presetup-mac: Install docker and docker-compose directly instead of brew to match the Docker server version 176 | - Added support to setup scripts to test different branches. E.g. `BOOT2DOCKER_TEST_ENVIRONMENT=develop setup.sh` 177 | - Updated documentation 178 | 179 | ## 0.13.0 (2015-06-18) 180 | 181 | - Split install scripts into two pieces: prerequisites installation (optional) and actual box installation. 182 | - Automatic installation is now supported on Windows! 183 | - vhost-proxy service - adds ability to use a single shared IP address for multiple web projects running concurrently. 184 | - VirtualBox network adapters performance adjustments (using `virtio` on the NAT interface). Resolves #12. 185 | - Added bash to avoid shell script compatibility issues and updated all shell scripts to use `#/bin/bash` header. Resolves #17. 186 | - Documentation updates. 187 | 188 | ## 0.12.1 (2015-06-06) 189 | 190 | - Minor fixes in the setup.sh script for Mac 191 | 192 | ## 0.12.0 (2015-05-07) 193 | 194 | - Use our own vagrant box - [blinkreaction/boot2docker](https://vagrantcloud.com/blinkreaction/boxes/boot2docker) 195 | - Updated Docker to v1.6.0 196 | - Updated Docker Compose to v1.2.0 197 | - [SMB2 (experimental)] sync folder option for Windows - complete automation of SMB sharing setup. 198 | - Automatically start containers if docker-compose.yml is present in the Vagrantfile directory (single project mode) 199 | - Miscellaneous code cleanup 200 | 201 | ## 0.11.1 (2015-04-09) 202 | 203 | - Hotfix: added check for empty hosts in vagrant.yml 204 | 205 | ## 0.11.0 (2015-04-09) 206 | 207 | - Using semantic versioning and tracking changes in the CHANGELOG.md file 208 | - All configuration moved into vagrant.yml 209 | - Refactored synced folders setup 210 | - Focused on better Windows support with SMB and rsync 211 | - Added an experimental `smb2` synced folder option, which does not require running vagrant as admin, but requires initial manual setup. 212 | - rsync can now be done per project instead of the whole folder 213 | - Documentation overhaul 214 | - Fixes in setup.sh - making sure brew formulae are up to date. 215 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Boot2docker Vagrant Box 2 | 3 | Boot2docker Vagrant box for optimized Docker and Docker Compose use on Mac and Windows. 4 | 5 | 6 | ## What is this? 7 | 8 | This is a temporary solution to achieve better performance with synced folders and docker data volumes on Mac and Windows. 9 | 10 | The stock boot2docker/docker-machine mounts host volumes via VirtualBox Guest Additions (vboxsf) mode, which is is terribly slow. Much better performance can be achieved with **nfs** (Mac), **smb** (Windows) or **rsync** (Mac and Windows). 11 | 12 | 13 | ## Prerequisites 14 | 1. [VirtualBox](https://www.virtualbox.org/) 5.1.x 15 | 2. [Vagrant](https://www.vagrantup.com/) 1.8.5+ 16 | 3. [Babun](http://babun.github.io) - A Linux-type shell + [winpty](https://github.com/rprichard/winpty), **Windows only** 17 | 18 | For best result and a clean setup it is recommended to remove any previous versions of VirtualBox, Vagrant, boot2docker, docker and docker-compose. 19 | 20 | Automatic **installation** and **updates** of prerequisites is available via the one-liners below. 21 | **Make sure to stop all VirtualBox VMs prior to performing updates.** 22 | 23 | Note: If you already have brew/cask and necessary versions of VirtualBox and Vagrant installed, 24 | prefer to install them manually or would like to not update these components automatically, 25 | prefix the command with `B2D_INSTALL_MODE=docker `. 26 | 27 | **Mac** 28 | 29 | Prerequisites are installed using **brew/cask** (brew and cask will be installed if missing). 30 | 31 | bash <(curl -s https://raw.githubusercontent.com/blinkreaction/boot2docker-vagrant/master/scripts/presetup-mac.sh) 32 | 33 | **Windows** 34 | 35 | **All automated scripts and instructions in this project assume using Babun shell and are not tested with other shells.** 36 | 37 | Prerequisites are installed using **babun** and **chocolatey** (chocolatey will be installed if missing). 38 | 39 | bash <(curl -s https://raw.githubusercontent.com/blinkreaction/boot2docker-vagrant/master/scripts/presetup-win.sh) 40 | 41 | 42 | 43 | ## Setup and usage 44 | 45 | ### Automatic installation 46 | 47 | Designate a root folder that the VM will have access to (e.g. `~/Projects`) and run there: 48 | 49 | bash <(curl -s https://raw.githubusercontent.com/blinkreaction/boot2docker-vagrant/master/scripts/setup.sh) 50 | 51 | ### Manual installation 52 | 53 | Use these steps if you have VirtualBox and/or Vagrant already installed or prefer/need to install them manually. 54 | 55 | 1. Copy `Vagrantfile` and `vagrant.yml` into a designated folder 56 | 2. Inside the folder run 57 | 58 | ``` 59 | vagrant up 60 | ``` 61 | 62 | 3. Verify your setup by checking docker client and server versions 63 | 64 | ``` 65 | docker version 66 | ``` 67 | 68 | 69 | ## Documentation 70 | 71 | - [Synced folders](docs/synced-folders.md) 72 | - [VirtualBox VM settings](docs/vm-settings.md) 73 | - [Networking](docs/networking.md) 74 | - [Troubleshooting](docs/troubleshooting.md) 75 | - [Tips](docs/tips.md) 76 | 77 | 78 | ## License 79 | 80 | The MIT License (MIT) 81 | 82 | Copyright (c) 2015 BlinkReaction 83 | 84 | Permission is hereby granted, free of charge, to any person obtaining a copy 85 | of this software and associated documentation files (the "Software"), to deal 86 | in the Software without restriction, including without limitation the rights 87 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 88 | copies of the Software, and to permit persons to whom the Software is 89 | furnished to do so, subject to the following conditions: 90 | 91 | The above copyright notice and this permission notice shall be included in all 92 | copies or substantial portions of the Software. 93 | 94 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 95 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 96 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 97 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 98 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 99 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 100 | SOFTWARE. 101 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 1.7.1 -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # UI Object for console interactions. 2 | @ui = Vagrant::UI::Colored.new 3 | 4 | # Install required plugins if not present. 5 | required_plugins = ["vagrant-triggers", "vagrant-gatling-rsync"] 6 | required_plugins.each do |plugin| 7 | need_restart = false 8 | unless Vagrant.has_plugin? plugin 9 | system "vagrant plugin install #{plugin}" 10 | need_restart = true 11 | end 12 | exec "vagrant #{ARGV.join(' ')}" if need_restart 13 | end 14 | 15 | # Determine if we are on Windows host or not. 16 | is_windows = Vagrant::Util::Platform.windows? 17 | 18 | # Determine paths. 19 | vagrant_root = File.dirname(__FILE__) # Vagrantfile location 20 | if is_windows 21 | vagrant_mount_point = `cygpath #{vagrant_root}`.strip! # Remove trailing \n 22 | vagrant_mount_point = vagrant_mount_point.gsub(/\/cygdrive/, '') # Remove '/cygdrive' prefix 23 | else 24 | vagrant_mount_point = vagrant_root 25 | end 26 | 27 | vagrant_folder_name = File.basename(vagrant_root) # Folder name only. Used as the SMB share name. 28 | 29 | # Use vagrant.yml for local VM configuration overrides. 30 | require 'yaml' 31 | if !File.exist?(vagrant_root + '/vagrant.yml') 32 | @ui.error 'Configuration file not found! Please copy vagrant.yml.dist to vagrant.yml and try again.' 33 | exit 34 | end 35 | $vconfig = YAML::load_file(vagrant_root + '/vagrant.yml') 36 | 37 | if is_windows 38 | require 'win32ole' 39 | # Determine if Vagrant was launched from the elevated command prompt. 40 | running_as_admin = ((`reg query HKU\\S-1-5-19 2>&1` =~ /ERROR/).nil? && is_windows) 41 | 42 | # Run command in an elevated shell. 43 | def windows_elevated_shell(args) 44 | command = 'cmd.exe' 45 | args = "/C #{args} || timeout 10" 46 | shell = WIN32OLE.new('Shell.Application') 47 | shell.ShellExecute(command, args, nil, 'runas') 48 | end 49 | 50 | # Method to create the user and SMB network share on Windows. 51 | def windows_net_share(share_name, path) 52 | # Add the vagrant user if it does not exist. 53 | smb_username = $vconfig['synced_folders']['smb_username'] 54 | smb_password = $vconfig['synced_folders']['smb_password'] 55 | 56 | command_user = "net user #{smb_username} || ( net user #{smb_username} #{smb_password} /add && WMIC USERACCOUNT WHERE \"Name='vagrant'\" SET PasswordExpires=FALSE )" 57 | @ui.info "Adding vagrant user" 58 | windows_elevated_shell command_user 59 | 60 | # Add the SMB share if it does not exist. 61 | command_share = "net share #{share_name} || net share #{share_name}=#{path} /grant:#{smb_username},FULL" 62 | @ui.info "Adding vagrant SMB share" 63 | windows_elevated_shell command_share 64 | 65 | # Set folder permissions. 66 | command_permissions = "icacls #{path} /grant #{smb_username}:(OI)(CI)M" 67 | @ui.info "Setting folder permissions" 68 | windows_elevated_shell command_permissions 69 | end 70 | 71 | # Method to remove the user and SMB network share on Windows. 72 | def windows_net_share_remove(share_name) 73 | smb_username = $vconfig['synced_folders']['smb_username'] 74 | 75 | command_user = "net user #{smb_username} /delete || echo 'User #{smb_username} does not exist' && timeout 10" 76 | windows_elevated_shell command_user 77 | 78 | command_share = "net share #{share_name} /delete || echo 'Share #{share_name} does not exist' && timeout 10" 79 | windows_elevated_shell command_share 80 | end 81 | else 82 | # Determine if Vagrant was launched with sudo (as root). 83 | running_as_root = (Process.uid == 0) 84 | end 85 | 86 | # Vagrant should NOT be run as root/admin. 87 | if running_as_root 88 | # || running_as_admin 89 | @ui.error "Vagrant should be run as a regular user to avoid issues." 90 | exit 91 | end 92 | 93 | ###################################################################### 94 | 95 | # Vagrant Box Configuration # 96 | Vagrant.require_version ">= 1.8.5" 97 | 98 | Vagrant.configure("2") do |config| 99 | config.vm.define "boot2docker" 100 | 101 | config.vm.box = "blinkreaction/boot2docker" 102 | config.vm.box_version = "1.12.1" 103 | config.vm.box_check_update = true 104 | 105 | ## Network ## 106 | 107 | box_ip = $vconfig['ip']['primary'] # e.g. 192.168.10.10 108 | host_ip = box_ip.gsub(/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/, '\1.\2.\3.1') # e.g. 192.168.10.1 109 | 110 | # Primary private network IP (default: 192.168.10.10) 111 | # Using Intel PRO/1000 MT Desktop [82540EM] network adapter - shows slightly better performance compared to "virtio". 112 | config.vm.network "private_network", ip: box_ip, nic_type: "82540EM" 113 | # Addtional IP addresses (see vagrant.yml) 114 | $vconfig['ip']['additional'].each do |private_ip| 115 | config.vm.network "private_network", ip: private_ip, nic_type: "82540EM" 116 | end unless $vconfig['ip']['additional'].nil? 117 | 118 | #################################################################### 119 | ## Synced folders configuration ## 120 | 121 | synced_folders = $vconfig['synced_folders'] 122 | # nfs: Better performance on Mac 123 | if synced_folders['type'] == "nfs" && !is_windows 124 | @ui.success "Using nfs synced folder option" 125 | config.vm.synced_folder vagrant_root, vagrant_mount_point, 126 | type: "nfs", 127 | mount_options: ["nolock", "vers=3", "tcp"] 128 | config.nfs.map_uid = Process.uid 129 | config.nfs.map_gid = Process.gid 130 | # nfs2: Optimized NFS settings for even better performance on Mac, experimental 131 | elsif ( synced_folders['type'] == "nfs2" || synced_folders['type'] == "default" ) && !is_windows 132 | @ui.success "Using nfs2 synced folder option" 133 | config.vm.synced_folder vagrant_root, vagrant_mount_point, 134 | type: "nfs", 135 | mount_options: ["nolock", "noacl", "nocto", "noatime", "nodiratime", "vers=3", "tcp", "actimeo=2"] 136 | config.nfs.map_uid = Process.uid 137 | config.nfs.map_gid = Process.gid 138 | # smb: Better performance on Windows. Requires Vagrant to be run with admin privileges. 139 | elsif synced_folders['type'] == "smb" && is_windows 140 | @ui.success "Using smb synced folder option" 141 | config.vm.synced_folder vagrant_root, vagrant_mount_point, 142 | type: "smb", 143 | smb_username: synced_folders['smb_username'], 144 | smb_password: synced_folders['smb_password'] 145 | # smb2: Better performance on Windows. Does not require running vagrant as admin. 146 | elsif ( synced_folders['type'] == "smb2" || synced_folders['type'] == "default" ) && is_windows 147 | @ui.success "Using smb2 synced folder option" 148 | 149 | if $vconfig['synced_folders']['smb2_auto'] 150 | # Create the share before 'up'. 151 | config.trigger.before :up, :stdout => true, :force => true do 152 | info 'Setting up SMB user and share' 153 | windows_net_share vagrant_folder_name, vagrant_root 154 | end 155 | 156 | # Remove the share after 'halt'. 157 | config.trigger.after :destroy, :stdout => true, :force => true do 158 | info 'Removing SMB user and share' 159 | windows_net_share_remove vagrant_folder_name 160 | end 161 | end 162 | 163 | # Mount the share in boot2docker. 164 | config.vm.provision "shell", run: "always" do |s| 165 | s.inline = <<-SCRIPT 166 | mkdir -p vagrant $2 167 | mount -t cifs -o uid=`id -u docker`,gid=`id -g docker`,noperm,sec=ntlm,username=$3,pass=$4,dir_mode=0777,file_mode=0777 //$5/$1 $2 168 | SCRIPT 169 | s.args = "#{vagrant_folder_name} #{vagrant_mount_point} #{$vconfig['synced_folders']['smb_username']} #{$vconfig['synced_folders']['smb_password']} #{host_ip}" 170 | end 171 | # rsync: the best performance, cross-platform platform, one-way only. 172 | elsif synced_folders['type'] == "rsync" 173 | @ui.success "Using rsync synced folder option" 174 | 175 | # Construct and array for rsync_exclude 176 | rsync_exclude = [] 177 | unless synced_folders['rsync_exclude'].nil? 178 | for item in synced_folders['rsync_exclude'] do 179 | rsync_exclude.push(item) 180 | end 181 | end 182 | 183 | # Only sync explicitly listed folders. 184 | if synced_folders['rsync_folders'].nil? 185 | @ui.error "ERROR: 'folders' list cannot be empty when using 'rsync' sync type. Please check your vagrant.yml file." 186 | exit 187 | else 188 | for synced_folder in synced_folders['rsync_folders'] do 189 | config.vm.synced_folder "#{vagrant_root}/#{synced_folder}", "#{vagrant_mount_point}/#{synced_folder}", 190 | type: "rsync", 191 | rsync__exclude: rsync_exclude, 192 | rsync__args: ["--archive", "--delete", "--compress", "--whole-file"] 193 | end 194 | end 195 | # Configure vagrant-gatling-rsync 196 | config.gatling.rsync_on_startup = false 197 | config.gatling.latency = synced_folders['rsync_latency'] 198 | config.gatling.time_format = "%H:%M:%S" 199 | 200 | # Launch gatling-rsync-auto in the background 201 | if synced_folders['rsync_auto'] && !is_windows 202 | [:up, :reload, :resume].each do |trigger| 203 | config.trigger.after trigger do 204 | success "Starting background rsync-auto process..." 205 | info "Run 'tail -f #{vagrant_root}/rsync.log' to see rsync-auto logs." 206 | # Kill the old sync process 207 | `kill $(pgrep -f rsync-auto) > /dev/null 2>&1 || true` 208 | # Start a new sync process in background 209 | `vagrant gatling-rsync-auto >> rsync.log &` 210 | end 211 | end 212 | [:halt, :suspend, :destroy].each do |trigger| 213 | config.trigger.before trigger do 214 | # Kill rsync-auto process 215 | success "Stopping background rsync-auto process..." 216 | `kill $(pgrep -f rsync-auto) > /dev/null 2>&1 || true` 217 | `rm -f rsync.log` 218 | end 219 | end 220 | end 221 | # vboxsf: reliable, cross-platform and terribly slow performance 222 | elsif synced_folders['type'] == "vboxsf" 223 | @ui.warn "WARNING: Using the SLOWEST folder sync option (vboxsf)" 224 | config.vm.synced_folder vagrant_root, vagrant_mount_point 225 | # Warn if neither synced_folder not individual_mounts is enabled 226 | elsif synced_folders['individual_mounts'].nil? 227 | @ui.error "ERROR: Synced folders not enabled or misconfigured. The VM will not have access to files on the host." 228 | end 229 | 230 | # Individual mounts 231 | unless synced_folders['individual_mounts'].nil? 232 | @ui.success "Using individual_mounts synced folder option" 233 | for synced_folder in synced_folders['individual_mounts'] do 234 | if synced_folder['type'] == 'vboxsf' 235 | config.vm.synced_folder synced_folder['location'], synced_folder['mount'], 236 | mount_options: [synced_folder['options']] 237 | elsif synced_folder['type'] == 'nfs' 238 | config.vm.synced_folder synced_folder['location'], synced_folder['mount'], 239 | type: "nfs", 240 | mount_options: [synced_folder['options']] 241 | end 242 | end 243 | end 244 | 245 | # Fix default vagrant share. 246 | # TODO: test and remove once Vagrant v1.8.6 is out. 247 | config.vm.synced_folder ".", "/vagrant", owner: 1000, group: 50 248 | 249 | # Make host home directory available to containers in /.home 250 | # TODO: test and remove hardcoded owner and group below once Vagrant v1.8.6 is out. 251 | if File.directory?(File.expand_path("~")) 252 | config.vm.synced_folder "~", "/.home", owner: 1000, group: 50 253 | end 254 | 255 | ###################################################################### 256 | 257 | ## VirtualBox VM settings. 258 | 259 | config.vm.provider "virtualbox" do |v| 260 | v.gui = $vconfig['v.gui'] # Set to true for debugging. Will unhide VM's primary console screen. 261 | v.name = vagrant_folder_name + "_boot2docker" # VirtualBox VM name. 262 | v.cpus = $vconfig['v.cpus'] # CPU settings. VirtualBox works much better with a single CPU. 263 | v.memory = $vconfig['v.memory'] # Memory settings. 264 | 265 | # Use VirtualBox DNS proxy mode (but not the resolver mode). 266 | # See https://www.virtualbox.org/manual/ch09.html#nat-adv-dns 267 | # and https://www.virtualbox.org/manual/ch09.html#nat_host_resolver_proxy 268 | # Also see https://github.com/docker/machine/pull/1069 for a different perspective on this. 269 | v.customize ['modifyvm', :id, '--natdnsproxy1', 'on'] 270 | v.customize ['modifyvm', :id, '--natdnshostresolver1', 'off'] 271 | end 272 | 273 | ## Provisioning scripts ## 274 | 275 | # Pass vagrant_root variable to the VM and cd into the directory upon login. 276 | config.vm.provision "shell", run: "always" do |s| 277 | s.inline = <<-SCRIPT 278 | echo "export VAGRANT_ROOT=$1" >> /home/docker/.profile 279 | echo "cd $1" >> /home/docker/.ashrc 280 | SCRIPT 281 | s.args = "#{vagrant_mount_point}" 282 | end 283 | 284 | # Install dsh tool (Drude Shell) into VM's permanent storage. 285 | # https://github.com/blinkreaction/drude 286 | config.vm.provision "shell" do |s| 287 | s.inline = <<-SCRIPT 288 | # echo "Installing dsh (Drude Shell)..." 289 | sudo curl -sSL https://raw.githubusercontent.com/blinkreaction/drude/master/bin/dsh -o /var/lib/boot2docker/bin/dsh 290 | sudo chmod +x /var/lib/boot2docker/bin/dsh 291 | sudo ln -sf /var/lib/boot2docker/bin/dsh /usr/local/bin/dsh 292 | SCRIPT 293 | end 294 | 295 | # Let users provide credentials to log in to Docker Hub. 296 | if $vconfig['docker_registry_auth'] 297 | config.vm.provision "trigger", :option => "value" do |trigger| 298 | trigger.fire do 299 | info 'Authenticating with the Docker registry...' 300 | system "docker -H localhost:2375 login" 301 | end 302 | end 303 | config.vm.provision "file", source: "~/.docker/config.json", destination: ".docker/config.json" 304 | end 305 | 306 | # System-wide dnsmasq service for DNS discovery and name resolution 307 | config.vm.provision "shell", privileged: false do |s| 308 | s.inline = <<-SCRIPT 309 | echo "Setting up system-wide DNS service... " 310 | docker run -d --name dns --label "group=system" --restart=always --privileged --userns=host \ 311 | -p 53:53/udp --cap-add=NET_ADMIN --dns 10.0.2.3 \ 312 | -v /var/run/docker.sock:/var/run/docker.sock \ 313 | blinkreaction/dns-discovery:stable > /dev/null 2>&1 314 | SCRIPT 315 | end 316 | 317 | # System-wide ssh-agent service. 318 | config.vm.provision "shell", privileged: false do |s| 319 | s.inline = <<-SCRIPT 320 | echo "Setting up system-wide ssh-agent service..." 321 | docker run -d --name ssh-agent --label "group=system" --restart=always --privileged --userns=host \ 322 | -v /var/run/docker.sock:/var/run/docker.sock \ 323 | blinkreaction/ssh-agent:stable > /dev/null 2>&1 324 | SCRIPT 325 | end 326 | 327 | # System-wide vhost-proxy service. 328 | # Containers must define a "VIRTUAL_HOST" environment variable to be recognized and routed by the vhost-proxy. 329 | if $vconfig['vhost_proxy'] 330 | config.vm.provision "shell", privileged: false do |s| 331 | s.inline = <<-SCRIPT 332 | echo "Setting up system-wide HTTP/HTTPS reverse proxy... " 333 | docker run -d --name vhost-proxy --label "group=system" --restart=always --privileged --userns=host \ 334 | -p 80:80 -p 443:443 \ 335 | -v /var/run/docker.sock:/tmp/docker.sock \ 336 | blinkreaction/nginx-proxy:stable > /dev/null 2>&1 337 | SCRIPT 338 | end 339 | end 340 | 341 | # Automatically start containers if docker-compose.yml is present in the current directory. 342 | # See "autostart" property in vagrant.yml. 343 | if File.file?('./docker-compose.yml') && $vconfig['compose_autostart'] 344 | config.vm.provision "shell", run: "always", privileged: false do |s| 345 | s.inline = <<-SCRIPT 346 | echo "Found docker-compose.yml in the root folder. Starting containers..." 347 | cd $1 348 | docker-compose up -d 349 | SCRIPT 350 | s.args = "#{vagrant_mount_point}" 351 | end 352 | end 353 | 354 | end 355 | -------------------------------------------------------------------------------- /docs/img/b2d-connection-timeout-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmakarov/boot2docker-vagrant/d41c2b9d5c11216102557b6d6ea0f78640d2d44b/docs/img/b2d-connection-timeout-1.png -------------------------------------------------------------------------------- /docs/img/b2d-connection-timeout-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmakarov/boot2docker-vagrant/d41c2b9d5c11216102557b6d6ea0f78640d2d44b/docs/img/b2d-connection-timeout-2.png -------------------------------------------------------------------------------- /docs/img/b2d-connection-timeout-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmakarov/boot2docker-vagrant/d41c2b9d5c11216102557b6d6ea0f78640d2d44b/docs/img/b2d-connection-timeout-3.png -------------------------------------------------------------------------------- /docs/img/network-adapter-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmakarov/boot2docker-vagrant/d41c2b9d5c11216102557b6d6ea0f78640d2d44b/docs/img/network-adapter-1.png -------------------------------------------------------------------------------- /docs/img/network-adapter-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lmakarov/boot2docker-vagrant/d41c2b9d5c11216102557b6d6ea0f78640d2d44b/docs/img/network-adapter-2.png -------------------------------------------------------------------------------- /docs/networking.md: -------------------------------------------------------------------------------- 1 | # Networking 2 | 3 | 4 | ## VM network settings 5 | 6 | The default box private network IP is `192.168.10.10`. 7 | To map additional IP addresses for use with multiple projects open `vagrant.yml` and ucomment respective lines: 8 | 9 | ```yaml 10 | hosts: 11 | - ip: 192.168.10.11 12 | - ip: 192.168.10.12 13 | - ip: 192.168.10.13 14 | ``` 15 | 16 | Project specific `:` mapping for containers is done in via docker-compose in `docker-compose.yml` 17 | 18 | 19 | ## vhost-proxy 20 | 21 | As an alternative to using dedicated IPs for different projects a built-in vhost-proxy container can be used. 22 | It binds to `192.168.10.10:80` (the default box IP address) and routes web requests based on the `Host` header. 23 | 24 | ### How to use 25 | - Set `vhost_proxy: true` in your vagrant.yml file and do a 'vagrant reload' 26 | - Set the `VIRTUAL_HOST` environment variable for the web container in your setup (e.g. `VIRTUAL_HOST=example.com`) 27 | - Add an entry in your hosts file (e.g. `/etc/hosts`) to point the domain to the default box IP (`192.168.10.10`) 28 | - As an alternative see [Wildcard DNS](#dns) instructions below 29 | - Multiple domain names can be separated by comas: `VIRTUAL_HOST=example.com,www.example.com` 30 | 31 | Example docker run 32 | 33 | ``` 34 | docker run --name nginx -d -e "VIRTUAL_HOST=example.com" nginx:latest 35 | ``` 36 | 37 | Example docker-compose.yml entry 38 | 39 | ``` 40 | # Web node 41 | web: 42 | image: nginx:latest 43 | ports: 44 | - "80" 45 | environment: 46 | - VIRTUAL_HOST=example.com 47 | ``` 48 | 49 | Example hosts file entry 50 | 51 | ``` 52 | 192.168.10.10 example.com 53 | ``` 54 | 55 | It is completely fine to use both the vhost-proxy approach and the dedicated IPs approach concurently: 56 | - `"80"` - expose port "80", docker will randomly pick an available port on the Docker Host 57 | - `"192.168.10.11:80:80"` - dedicated IP:port mapping 58 | 59 | 60 | ## DNS and service discovery 61 | 62 | ### DNS resolution 63 | 64 | The built-in `dns` container can be used to resolve all `*.drude` domain names to `192.168.10.10` (VM's primary IP address), where vhost-proxy listens on port 80. 65 | 66 | **Mac** 67 | 68 | ``` 69 | sudo mkdir -p /etc/resolver 70 | echo -e "\n# .drude domain resolution\nnameserver 192.168.10.10" | sudo tee -a /etc/resolver/drude 71 | ``` 72 | 73 | **Windows** 74 | 75 | On Windows add `192.168.10.10` as the primary DNS server and your LAN/ISP/Google DNS as secondary. 76 | 77 | 78 | ### Service discovery 79 | 80 | The built-in `dns` container can also be used for local DNS based service discovery. 81 | You can define an arbitrary domain name via the `DOMAIN_NAME` environment variable for any container and it will be resolved to the internal IP address of that container. 82 | 83 | **Example** 84 | 85 | ``` 86 | docker run --name nginx -d -e "DOMAIN_NAME=my-project.web.docker" nginx:latest 87 | docker run busybox ping my-project.web.docker -c 1 88 | ``` 89 | 90 | ``` 91 | PING my_project.web.docker (172.17.42.8): 56 data bytes 92 | 64 bytes from 172.17.42.8: seq=0 ttl=64 time=0.052 ms 93 | ... 94 | 95 | ``` 96 | 97 | Multiple domain names can be separated by comas: `DOMAIN_NAME=my-project.web.docker,www.my-project.web.docker` 98 | -------------------------------------------------------------------------------- /docs/synced-folders.md: -------------------------------------------------------------------------------- 1 | # Synced Folders 2 | 3 | This box supports all [Synced Folder](http://docs.vagrantup.com/v2/synced-folders/) options provided by Vagrant 4 | as well two custom optimized options : 5 | - vboxsf - native VirtualBox method, cross-platform, convenient and reliable, terribly slow 6 | - nfs: better performance and convenience on Mac 7 | - nfs2: optimized nfs settings, experimental (default on Mac) 8 | - smb: better performance and convenience on Windows. Requires Vagrant to be run with admin privileges (not recommended). 9 | - smb2: does not require running vagrant as admin (default on Windows). 10 | - rsync: best performance, cross-platform platform, one-way only 11 | 12 | Follow the instructions in the `vagrant.yml` file to switch between different sync options. 13 | The best balance between performance and convenience can be achieved with **nfs2** on Mac (default) and **smb2** on Windows (default). 14 | 15 | If you use rsync on Windows, you'll have to run `vagrant gatling-rsync-auto` in a separate terminal to keep the files in sync as you make changes. 16 | This is automated on Mac with `rsync_auto` set to `true` in `vagrant.yml`. 17 | 18 | 19 | ## Mac 20 | 21 | Option comparison for Mac Drupal developers (using `time drush si -y` as a test case): 22 | - vboxsf: 6x (slowest) 23 | - nfs: 1.3x 24 | - rsync: 1x (fastest) 25 | 26 | NFS provides good performance and convenience (used by default on Mac) 27 | 28 | 29 | ## Windows 30 | 31 | Option comparison for Windows Drupal developers (using `time drush si -y` as a test case): 32 | - vboxsf: 5x (slowest) 33 | - smb: 2x 34 | - rsync: 1x (fastest) 35 | 36 | **smb** provides good performance and convenience (used by default on Windows) 37 | 38 | **smb vs smb2** 39 | 40 | Compared to **smb**, **smb2** does not require running vagrant as admin and does not prompt for username and password. 41 | You will receive several "elevated command prompt" prompts which you accept. 42 | Vagrant will automatically create a user, set correct file permissions, create the SMB share, and mount it. 43 | -------------------------------------------------------------------------------- /docs/tips.md: -------------------------------------------------------------------------------- 1 | # Tips 2 | 3 | ## Automate DOCKER_HOST variable export 4 | 5 | This is only necessary for manual instllations. [setup.sh](../scripts/setup.sh) script takes care of this for you. 6 | 7 | Add the following in your .bashrc, .zshrc, etc. file to automate the environment variable export: 8 | 9 | # Docker (default for Vagrant based boxes) 10 | export DOCKER_HOST=tcp://localhost:2375 11 | 12 | If you also have `$(boot2docker shellinit)` there, then make sure those lines go BEFORE it, e.g.: 13 | 14 | # Docker (default for Vagrant based boxes) 15 | export DOCKER_HOST=tcp://localhost:2375 16 | 17 | # boot2docker shellinit 18 | $(boot2docker shellinit) 19 | 20 | This way if boot2docker is NOT running, your `DOCKER_HOST` will default to `tcp://localhost:2375`. 21 | Otherwise `$(boot2docker shellinit)` will overwrite the variables and set `DOCKER_HOST` to point to the boot2docker VM. 22 | 23 | ## Vagrant control 24 | Vagrant can be controlled (e.g. `vagrant up`, `vagrant ssh`, `vagrant reload`, etc.) from the root directory of the Vagrantfile as well as from any subdirectory. This is very usefull when working with multiple projects in subdirectories. 25 | 26 | ## Sublime Text 3 users 27 | Add this to your user settings (Sublime Text > Preferences > Settings - User): 28 | 29 | { 30 | "atomic_save": false 31 | } 32 | 33 | ST3 does not update the ctime extended file attribute when saving a file. This leads to NFS not seeing the changes in a file unless the file size changes as well (i.e. changing a single symbol in a file with ST3 will not be visible over NFS). The setting above fixes that. 34 | -------------------------------------------------------------------------------- /docs/troubleshooting.md: -------------------------------------------------------------------------------- 1 | # Troubleshooting 2 | 3 | ## Boot2docker connection timeout 4 | 5 | **Symptoms** 6 | 7 | Boot2docker VM fails to boot after multiple "Warning: Connection timeout. Retrying..." messages. 8 | 9 | 10 | 11 | 12 | **Cause** 13 | 14 | Host machine does not have virtualization support (VT-x) or has it disabled. 15 | Confirm by attaching to the VM console. 16 | 17 | 18 | 19 | 20 | 21 | **Solution** 22 | 23 | Enable VT-x in BIOS. 24 | Machines without VT-x support won't work with Drude / boot2docker-vagrant / 64bit VirtualBox VMs. 25 | 26 | ## Various networking issues 27 | 28 | **Symptoms** 29 | 30 | - "Layer already being pulled by another client" 31 | - [Permission Denied while mounting NFS shared folders](https://github.com/blinkreaction/boot2docker-vagrant/issues/27) 32 | - [Stale NFS handle error](https://github.com/blinkreaction/drude/issues/20) 33 | 34 | **Cause** 35 | 36 | VirtualBox ships with a preconfigured DHCP server which gets in the way, sometimes in very unobvious cases. 37 | Sometimes the cause may not be the DHCP server, but a corrupt VM network adapter. 38 | 39 | **Solution** 40 | 41 | 1. Note the Host-only Adapter name used by the VM. 42 | 43 | 44 | 45 | 2. Open VirtualBox Preferences > Network > Host-only Netowrks and kill that adapter. 46 | 47 | 48 | 49 | 3. Restart the VM. 50 | -------------------------------------------------------------------------------- /docs/vm-settings.md: -------------------------------------------------------------------------------- 1 | 2 | # VirtualBox VM settings 3 | 4 | Open `vagrant.yml` file and edit respective values. 5 | 6 | - `v.gui` - Set to `true` for debugging. This will unhide VM's primary console screen. Default: `false`. 7 | - `v.memory` - Memory settings (MB). Default: `2048`. 8 | - `v.cpus: 1` - number of virtual CPU cores. Default: `1`. 9 | 10 | Please note, VirtualBox works much better with a single CPU in most cases, this it is not recommended to change the `v.cpus` value. 11 | -------------------------------------------------------------------------------- /scripts/presetup-mac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DOCKER_VERSION=1.12.1 4 | DOCKER_COMPOSE_VERSION=1.8.0 5 | 6 | # Console colors 7 | red='\033[0;31m' 8 | green='\033[0;32m' 9 | yellow='\033[1;33m' 10 | NC='\033[0m' 11 | 12 | echo-red () { echo -e "${red}$1${NC}"; } 13 | echo-green () { echo -e "${green}$1${NC}"; } 14 | echo-yellow () { echo -e "${yellow}$1${NC}"; } 15 | 16 | B2D_BRANCH="${B2D_BRANCH:-master}" 17 | B2D_INSTALL_MODE="${B2D_INSTALL_MODE:-full}" 18 | 19 | # VirtualBox and Vagrant dependencies 20 | if [[ "$B2D_INSTALL_MODE" == "full" ]] || [[ "$B2D_INSTALL_MODE" == "vm" ]] ; then 21 | # Homebrew installation 22 | echo-green "Installing Homebrew..." 23 | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 24 | 25 | # Update brew formulae 26 | echo-green "Updating brew formulae..." 27 | brew update 28 | 29 | # VirtualBox installation 30 | echo-green "Installing virtualbox..." 31 | brew cask install virtualbox 32 | # Kill the default adapter and DHCP server to avoid network issues down the road 33 | VBoxManage dhcpserver remove --netname HostInterfaceNetworking-vboxnet0 > /dev/null 2>&1 34 | VBoxManage hostonlyif remove vboxnet0 > /dev/null 2>&1 35 | 36 | # Vagrant installation 37 | echo-green "Installing vagrant..." 38 | brew cask install vagrant 39 | fi 40 | 41 | # Docker and other dependencies 42 | if [[ "$B2D_INSTALL_MODE" == "full" ]] || [[ "$B2D_INSTALL_MODE" == "docker" ]] ; then 43 | # Remove old docker version 44 | sudo rm -f /usr/local/bin/docker >/dev/null 2>&1 || true 45 | # Install docker 46 | echo-green "Installing docker cli v${DOCKER_VERSION}..." 47 | curl -sSL -O "https://get.docker.com/builds/$(uname -s)/$(uname -m)/docker-$DOCKER_VERSION.tgz" 48 | tar zxf docker-$DOCKER_VERSION.tgz 49 | sudo mv docker/* /usr/local/bin 50 | rm -rf docker-$DOCKER_VERSION* 51 | 52 | # Remove old docker-compose version 53 | sudo rm -f /usr/local/bin/docker-compose >/dev/null 2>&1 || true 54 | # Install docker-compose 55 | echo-green "Installing docker-compose v${DOCKER_COMPOSE_VERSION}..." 56 | sudo curl -sSL "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose 57 | sudo chmod +x /usr/local/bin/docker-compose 58 | fi 59 | -------------------------------------------------------------------------------- /scripts/presetup-win.cmd: -------------------------------------------------------------------------------- 1 | REM Installing Chocolatey 2 | @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin 3 | 4 | REM Installing virtualbox 5 | choco upgrade virtualbox -y 6 | 7 | REM Killing the default adapter and DHCP server to avoid network issues down the road 8 | "C:\Program Files\Oracle\VirtualBox\VBoxManage" dhcpserver remove --netname "HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter" 9 | "C:\Program Files\Oracle\VirtualBox\VBoxManage" hostonlyif remove "VirtualBox Host-Only Ethernet Adapter" 10 | 11 | REM Installing vagrant 12 | choco upgrade vagrant -y 13 | -------------------------------------------------------------------------------- /scripts/presetup-win.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DOCKER_VERSION=1.12.1 4 | DOCKER_COMPOSE_VERSION=1.8.0 5 | # These two shouldbe changes together. Always check https://github.com/rprichard/winpty/releases for the current version. 6 | WINPTY_VERSION=0.4.0 7 | CYGWIN_VERSION=2.5.2 8 | ## 9 | 10 | # Console colors 11 | red='\033[0;31m' 12 | green='\033[0;32m' 13 | yellow='\033[1;33m' 14 | NC='\033[0m' 15 | 16 | echo-red () { echo -e "${red}$1${NC}"; } 17 | echo-green () { echo -e "${green}$1${NC}"; } 18 | echo-yellow () { echo -e "${yellow}$1${NC}"; } 19 | 20 | B2D_BRANCH="${B2D_BRANCH:-master}" 21 | B2D_INSTALL_MODE="${B2D_INSTALL_MODE:-full}" 22 | 23 | # VirtualBox and Vagrant dependencies 24 | if [[ "$B2D_INSTALL_MODE" == "full" ]] || [[ "$B2D_INSTALL_MODE" == "vm" ]] ; then 25 | # Install prerequisites via choco (virtualbox and vagrant) 26 | echo-green "Installing virtualbox and vagrant via choco..." 27 | curl -sSL https://raw.githubusercontent.com/blinkreaction/boot2docker-vagrant/${B2D_BRANCH}/scripts/presetup-win.cmd -o $WINDIR/Temp/presetup-win.cmd 28 | curl -sSL https://raw.githubusercontent.com/blinkreaction/boot2docker-vagrant/${B2D_BRANCH}/scripts/presetup-win.vbs -o $WINDIR/Temp/presetup-win.vbs 29 | echo-yellow "Setup needs administrator privileges to contiue..." 30 | cscript $WINDIR/Temp/presetup-win.vbs 31 | fi 32 | 33 | # Docker and other dependencies 34 | if [[ "$B2D_INSTALL_MODE" == "full" ]] || [[ "$B2D_INSTALL_MODE" == "docker" ]] ; then 35 | # Remove old docker version 36 | rm -f /usr/local/bin/docker >/dev/null 2>&1 || true 37 | # Install Docker 38 | echo-green "Installing docker cli v${DOCKER_VERSION}..." 39 | curl -sSL -O https://get.docker.com/builds/Windows/i386/docker-$DOCKER_VERSION.zip 40 | unzip docker-$DOCKER_VERSION.zip 41 | mv docker/* /usr/local/bin 42 | rm -rf docker-$DOCKER_VERSION* 43 | 44 | # Remove old docker-compose version 45 | rm -f /usr/local/bin/docker-compose >/dev/null 2>&1 || true 46 | # Install Docker Compose 47 | echo-green "Installing docker-compose v${DOCKER_COMPOSE_VERSION}..." 48 | curl -sSL https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-Windows-x86_64.exe -o /usr/local/bin/docker-compose.exe 49 | chmod +x /usr/local/bin/docker-compose.exe 50 | 51 | # Install winpty 52 | echo-green "Installing winpty (console) v$WINPTY_VERSION..." 53 | curl -sSL -O https://github.com/rprichard/winpty/releases/download/$WINPTY_VERSION/winpty-$WINPTY_VERSION-cygwin-$CYGWIN_VERSION-ia32.tar.gz 54 | tar -xf winpty-$WINPTY_VERSION-cygwin-$CYGWIN_VERSION-ia32.tar.gz 55 | mv winpty-$WINPTY_VERSION-cygwin-$CYGWIN_VERSION-ia32/bin/* /usr/local/bin 56 | rm -rf winpty-$WINPTY_VERSION-cygwin-$CYGWIN_VERSION-ia32* 57 | 58 | # Git settings 59 | echo-green "Adjusting git defaults..." 60 | git config --global core.autocrlf input 61 | git config --system core.longpaths true 62 | fi 63 | -------------------------------------------------------------------------------- /scripts/presetup-win.vbs: -------------------------------------------------------------------------------- 1 | Set objShell = CreateObject("Shell.Application") 2 | Set objWshShell = WScript.CreateObject("WScript.Shell") 3 | Set objWshProcessEnv = objWshShell.Environment("PROCESS") 4 | 5 | strPath = objWshShell.ExpandEnvironmentStrings( "%WINDIR%" ) 6 | strCommandLine = "/c " & strPath & "\Temp\presetup-win.cmd & pause" 7 | strApplication = "cmd.exe" 8 | 9 | objShell.ShellExecute strApplication, strCommandLine, "", "runas" 10 | -------------------------------------------------------------------------------- /scripts/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Docker Host IP 4 | DOCKER_HOST_IP='192.168.10.10' 5 | 6 | # Console colors 7 | red='\033[0;31m' 8 | green='\033[0;32m' 9 | yellow='\033[1;33m' 10 | NC='\033[0m' 11 | 12 | echo-red () { echo -e "${red}$1${NC}"; } 13 | echo-green () { echo -e "${green}$1${NC}"; } 14 | echo-yellow () { echo -e "${yellow}$1${NC}"; } 15 | 16 | # For testing 17 | if [ ! $B2D_BRANCH == "" ]; then 18 | echo-red "[b2d-setup] testing mode: environment = ${B2D_BRANCH}" 19 | else 20 | B2D_BRANCH='master' 21 | fi 22 | 23 | # Download Vagrantfile 24 | echo-green "Downloading Vagrantfile into the current directory..." 25 | curl -sO "https://raw.githubusercontent.com/blinkreaction/boot2docker-vagrant/${B2D_BRANCH}/Vagrantfile" 26 | 27 | # Download vagrant.yml 28 | echo-green "Downloading vagrant.yml into the current directory..." 29 | curl -sO "https://raw.githubusercontent.com/blinkreaction/boot2docker-vagrant/${B2D_BRANCH}/vagrant.yml" 30 | 31 | # Write DOCKER_HOST variable export to a matching .rc file based on the shell (bash or zsh) 32 | SOURCE_FILE='' 33 | DOCKER_HOST_EXPORT="\n# Docker (default for Vagrant based boxes)\nexport DOCKER_HOST=tcp://${DOCKER_HOST_IP}:2375\n" 34 | 35 | # Detect shell to write to the right .rc file 36 | if [[ $SHELL == '/bin/bash' || $SHELL == '/bin/sh' ]]; then SOURCE_FILE=".bash_profile"; fi 37 | if [[ $SHELL == '/bin/zsh' ]]; then SOURCE_FILE=".zshrc"; fi 38 | 39 | if [[ $SOURCE_FILE ]]; then 40 | # See if we already did this and skip if so 41 | grep -q "export DOCKER_HOST=tcp://${DOCKER_HOST_IP}:2375" $HOME/$SOURCE_FILE 42 | if [[ $? -ne 0 ]]; then 43 | echo-green "Adding automatic DOCKER_HOST export to $HOME/$SOURCE_FILE" 44 | echo -e $DOCKER_HOST_EXPORT >> $HOME/$SOURCE_FILE 45 | fi 46 | else 47 | echo-red "Cannot detect your shell. Please manually add the following to your respective .rc or .profile file:" 48 | echo -e "$DOCKER_HOST_EXPORT" 49 | fi 50 | 51 | if [[ $B2D_NO_AUTOSTART == '' ]]; then 52 | # Start the boot2docker VM 53 | echo-green "Starting the boot2docker VM..." 54 | vagrant up 55 | 56 | # Check that Docker works 57 | echo-green "Checking that everything is in place..." 58 | docker version && vagrant ssh -c 'docker-compose --version' 59 | if [[ $? -ne 0 ]]; then 60 | echo -e "${red}Something went wrong. Please review console output for possible clues.${NC}" 61 | exit 1 62 | else 63 | echo-green "Docker Host is up and running. Please restart your shell." 64 | fi 65 | fi 66 | -------------------------------------------------------------------------------- /vagrant.yml: -------------------------------------------------------------------------------- 1 | # Sync folders configuration 2 | synced_folders: 3 | # vboxsf - native VirtualBox method, cross-platform, convenient and reliable, terribly slow 4 | # nfs: better performance and convenience on Mac 5 | # nfs2: optimized nfs settings, experimental (default on Mac) 6 | # smb: better performance and convenience on Windows. Requires Vagrant to be run with admin privileges (not recommended). 7 | # smb2: does not require running vagrant as admin (default on Windows). 8 | # rsync: best performance, cross-platform platform, one-way only 9 | # Run `vagrant rsync-auto` to start auto sync. 10 | # When using rsync sync type the "rsync_folders" list below is mandatory. 11 | # vboxsf: best compatibility and ease of setup, but poor performance. 12 | # default: defaults to nfs2 on Mac and smb2 on Windows. 13 | # '': disable synced folders. Useful in case you want to use 'individual_mounts' option below. 14 | type: 'default' 15 | # smb_user, smb_password - The username and password used for authentication to mount the SMB mount. 16 | # This is usually your Windows username and password, unless you created a dedicated user for vagrant. 17 | # If using the 'smb2' type above the user and share will be configured automatically. 18 | smb_username: 'vagrant' 19 | smb_password: 'P@ssW0rd1!' 20 | # Create smb share on vagrant up (if type smb2). Set to false if you want to or already created the user and the smb share manually. 21 | # If false, the share name should be equal to the directory name in which Vagrantfile is located. 22 | smb2_auto: true 23 | # List of folders to sync with rsync. These should be subfolder names within the folder (e.g. "drupal7") 24 | # Uncomment and add folders per the example below as neccessary. 25 | # Note: you'll have to run `vagrant rsync-auto` in the background to keep the files in sync as you make changes 26 | rsync_folders: 27 | #- "projectA" # rsync projectA folder 28 | #- "projectB" # rsync projectB folder 29 | #- "" # rsync the whole folder. WARNING: don't do this if your folder is big. 30 | # Coalescing threshold in seconds for https://github.com/smerrill/vagrant-gatling-rsync 31 | rsync_latency: 0.5 32 | # Start rsync-auto automatically (Mac only for now) 33 | rsync_auto: true 34 | # Patterns excluded from rsync. Passed as --exclude to rsync. 35 | rsync_exclude: 36 | - ".git/" 37 | #- "files/" 38 | # List of folders to mount individually. This is really only needed in the case where you want a container to write 39 | # something back to the Host OS. If that describes your situation, use type = vboxsf. If you just want more control 40 | # over what's mounted, go with type = nfs, which is much faster. 41 | individual_mounts: 42 | #- location: './logs' 43 | # mount: '/home/docker/logs' 44 | # type: 'vboxsf' 45 | # options: 'uid=501,gid=20' 46 | #- location: './logs' 47 | # mount: '/home/docker/logs' 48 | # type: 'nfs' 49 | # options: 'nolock,vers=3,tcp' 50 | 51 | # VirtualBox VM settings 52 | v.gui: false # Set to true for debugging. Will unhide VM's primary console screen. 53 | v.memory: 1024 # Memory settings. 54 | v.cpus: 1 # CPU settings. VirtualBox works much better with a single CPU. 55 | 56 | # Network settings 57 | ip: 58 | # The default box private network IP is 192.168.10.10 59 | primary: 192.168.10.10 60 | # Uncomment lines below to map additional IP addresses for use with multiple projects. 61 | # Project specific `:` mapping for containers is done in via docker-compose in `docker-compose.yml` 62 | additional: 63 | #- 192.168.10.11 64 | #- 192.168.10.12 65 | #- 192.168.10.13 66 | 67 | # Registry authentication. If your machine uses a private image, you must log in 68 | # to the registry before running docker-machine up. This is especially useful 69 | # when combined with compose_autostart: true. 70 | docker_registry_auth: false 71 | 72 | # Automatically start containers if docker-compose.yml is present in the current directory (default: false). 73 | compose_autostart: false 74 | 75 | # vhost-proxy (optional, enabled) 76 | # Use a reverse proxy to map host name to containers. 77 | # This is an alternative to using dedicated IP addresses in the 'hosts' section above. 78 | # Containers must define a "VIRTUAL_HOST" environment variable to be recognized and routed by the vhost-proxy. 79 | vhost_proxy: true 80 | --------------------------------------------------------------------------------