Skip to content
This repository was archived by the owner on Dec 1, 2018. It is now read-only.

Commit 301a9a6

Browse files
committed
Merge branch 'release/v0.13.0'
2 parents 7f5ca7d + a6081e0 commit 301a9a6

8 files changed

+171
-48
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## 0.13.0 (2015-06-18)
4+
5+
- Split install scripts into two pieces: prerequisites installation (optional) and actual box installation.
6+
- Automatic installation is now supported on Windows!
7+
- vhost-proxy service - adds ability to use a single shared IP address for multiple web projects running concurently.
8+
- VirtualBox network adapters performance adjustments (using `virtio` on the NAT interface). Resolves #12.
9+
- Added bash to avoid shell script compatibility issues and updated all shell scripts to use `#/bin/bash` header. Resolves #17.
10+
- Documentation updates.
11+
312
## 0.12.1 (2015-06-06)
413

514
- Minor fixes in the setup.sh script for Mac

README.md

+68-14
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,60 @@
22
Boot2docker Vagrant box for optimized Docker and Docker Compose use on Mac and Windows.
33

44
## What is this?
5-
This is a temporary solution to achive better performance with synced folders and docker data volumes on Mac and Windows.
5+
This is a temporary solution to achieve better performance with synced folders and docker data volumes on Mac and Windows.
66
The stock boot2docker currently mounts host volumes via the default VirtualBox Guest Additions (vboxfs) mode, which is terribly slow. Much better performance can be achieved with NFS, SMB or rsync.
77

88
<a name="requirements"></a>
9-
## Requirements
9+
## Prerequisites
1010
1. [VirtualBox](https://www.virtualbox.org/) 4.3.20+
1111
2. [Vagrant](https://www.vagrantup.com/) 1.6.3+
1212
3. [Git](http://git-scm.com/)
1313

14+
Proceed to [Setup and usage](#setup) if you already have all prerequisites installed or prefer to install some/all manually.
15+
Automatic installation of prerequisites is available via the following one-liners.
16+
17+
**Mac**
18+
19+
On Mac prerequisites are installed using **brew/cask** (brew and cask will be installed if missing).
20+
21+
curl -s https://raw.githubusercontent.com/blinkreaction/boot2docker-vagrant/master/presetup-mac.sh | bash
22+
23+
**Windows**
24+
25+
On Windows prerequisites are installed using **chocolatey** (chocolatey will be installed if missing).
26+
27+
1. Run Command Prompt as administrator
28+
2. Copy and and paste there the code from [presetup-win.cmd](https://raw.githubusercontent.com/blinkreaction/boot2docker-vagrant/master/presetup-win.cmd)
29+
1430
<a name="setup"></a>
1531
## Setup and usage
1632

17-
### Automatic installation (Mac only)
33+
### Automatic installation (Mac and Windows)
1834

19-
The following tools will be installed: brew, cask, virtualbox, vagrant, docker, docker-compose.
20-
In case you already have some of these installed (virtualbox, vagrant), it may be best (though not required) to either follow the manual install process or uninstall them before proceeding.
35+
**On Windows** Git Bash is the recommended option to run console commands.
36+
If you are having any issues, please check if they can be reproduced in Git Bash.
2137

2238
Run the following command within your `<Projects>` (shared boo2docker VM for multiple projects, recommended) or `<Project>` (dedicated boot2docker VM) directory:
2339

2440
curl -s https://raw.githubusercontent.com/blinkreaction/boot2docker-vagrant/master/setup.sh | bash
2541

26-
### Manual installation (Windows)
27-
28-
**On Windows** Git Bash is the recommended option to run console commands.
29-
If you are having any issues, please check if they can be reproduced in Git Bash.
42+
### Manual installation (Mac and Windows)
3043

3144
1. Copy `Vagrantfile` and `vagrant.yml.dist` files from this repo into your `<Projects>` (shared boo2docker VM for multiple projects, recommended) or `<Project>` (dedicated boot2docker VM) directory.
3245
2. Rename `vagrant.yml.dist` to `vagrant.yml`
33-
3. Launch Git Bash
34-
4. cd to `</path/to/project>`, start the VM and log into it
46+
3. Launch Terminal (Mac) or Git Bash (Windows)
47+
4. cd to `</path/to/project>`, start the VM
3548

3649
```
3750
cd </path/to/project>
3851
vagrant up
39-
vagrant ssh
4052
```
4153
42-
5. Verify installation (you are in the boot2docker VM at this point)
54+
5. Verify installation
4355
4456
```
4557
docker version
46-
docker-compose --version
58+
vagrant ssh -c 'docker-compose --version'
4759
```
4860
4961
<a name="synced-folders"></a>
@@ -64,6 +76,8 @@ In addition to the stock SMB synced folders option this box provides an experime
6476
With the **SMB2** option you will receive several "elevated command prompt" prompts which you accept.
6577
No need to enter usernames and passwords unlike the stock SMB option Vagrant ships with.
6678
79+
If you use rsync, you'll have to run `vagrant rsync-auto` in a separate terminal to keep the files in sync as you make changes.
80+
6781
<a name="synced-folders-mac"></a>
6882
### Mac
6983
@@ -115,6 +129,7 @@ To use rsync on Windows:
115129
2. Choose `rsync` as the sync type in the `vagrant.yml` file.
116130
3. Provide an explicit list of folders to sync in the `vagrant.yml` file (`folders` sequence).
117131
4. Reload the VM: `vagrant reload`
132+
5. Run `vagrant rsync-auto` to keep the files in sync as you make changes.
118133
119134
<a name="vm-settings"></a>
120135
## VirtualBox VM settings
@@ -142,6 +157,45 @@ hosts:
142157

143158
Project specific `<IP>:<port>` mapping for containers is done in via docker-compose in `docker-compose.yml`
144159

160+
# vhost-proxy
161+
162+
As an alternative to using dedicated IPs for different projects a built-in vhost-proxy container can be used.
163+
It binds to `192.168.10.10:80` (the default box IP address) and routes web requests based on the `Host` header.
164+
165+
### How to use
166+
- Set `vhost_proxy: true` in your vagrant.yml file and do a 'vagrant reload'
167+
- Set the `VIRTUAL_HOST` environment variable for the web container in your setup (e.g. `VIRTUAL_HOST=example.com`)
168+
- Add an entry in your hosts file (e.g. `/etc/hosts`) to point the domain to the default box IP (`192.168.10.10`)
169+
170+
Example docker run
171+
172+
```
173+
docker run --name nginx -d -e "VIRTUAL_HOST=example.com" nginx:latest
174+
```
175+
176+
Example docker-compose.yml entry
177+
178+
```
179+
# Web node
180+
web:
181+
image: nginx:latest
182+
ports:
183+
- "80"
184+
environment:
185+
- VIRTUAL_HOST=example.com
186+
```
187+
188+
Example hosts file entry
189+
190+
```
191+
192.168.10.10 example.com
192+
```
193+
194+
It is completely fine to use both the vhost-proxy approach and the dedicated IPs approach concurently:
195+
- `"80"` - expose port "80", docker will randomly pick an available port on the Docker Host
196+
- `"192.168.10.11:80:80"` - dedicated IP:port mapping
197+
198+
145199
## Tips
146200

147201
### Automate DOCKER_HOST variable export

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.12.1
1+
0.13.0

Vagrantfile

+32-1
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ Vagrant.configure("2") do |config|
9999

100100
# The default box private network IP is 192.168.10.10
101101
# Configure additional IP addresses in vagrant.yml
102+
# Using Intel PRO/1000 MT Server [82545EM] network adapter - shows slightly better performance compared to "virtio".
102103
$vconfig['hosts'].each do |host|
103-
config.vm.network "private_network", ip: host['ip']
104+
config.vm.network "private_network", ip: host['ip'], nic_type: "82545EM"
104105
end unless $vconfig['hosts'].nil?
105106

106107
####################################################################
@@ -175,6 +176,11 @@ Vagrant.configure("2") do |config|
175176
v.name = vagrant_folder_name + "_boot2docker" # VirtualBox VM name.
176177
v.cpus = $vconfig['v.cpus'] # CPU settings. VirtualBox works much better with a single CPU.
177178
v.memory = $vconfig['v.memory'] # Memory settings.
179+
180+
# Switch the base box NAT network adapters from "82545EM" to "virtio".
181+
# Default Intel adapters do not work well with docker...
182+
# See https://github.com/blinkreaction/boot2docker-vagrant/issues/13 for details.
183+
v.customize ["modifyvm", :id, "--nictype1", "virtio"]
178184
end
179185

180186
## Provisioning scripts ##
@@ -183,15 +189,26 @@ Vagrant.configure("2") do |config|
183189
# https://github.com/deis/deis/issues/2230#issuecomment-72701992
184190
config.vm.provision "shell" do |s|
185191
s.inline = <<-SCRIPT
192+
echo 'Disabling DOCKER_TLS...'
186193
echo 'DOCKER_TLS=no' >> /var/lib/boot2docker/profile
187194
/etc/init.d/docker restart
188195
SCRIPT
189196
end
190197

198+
# Install bash for compatibility with "#!/bin/bash" scripts.
199+
config.vm.provision "shell", run: "always", privileged: false do |s|
200+
s.inline = <<-SCRIPT
201+
echo 'Installing bash...'
202+
tce-load -wi bash.tcz > /dev/null 2>&1
203+
SCRIPT
204+
end
205+
191206
# Make docker-compose available inside boot2docker via a container.
192207
# https://github.com/docker/compose/issues/598#issuecomment-67762456
193208
config.vm.provision "shell", run: "always" do |s|
194209
s.inline = <<-SCRIPT
210+
echo 'Making docker-compose available inside boot2docker...'
211+
195212
DC_SCRIPT='
196213
#/bin/sh
197214
@@ -251,11 +268,25 @@ Vagrant.configure("2") do |config|
251268
SCRIPT
252269
end
253270

271+
# Start system-wide services.
272+
# vhost-proxy: https://github.com/jwilder/nginx-proxy
273+
# Containers must define a "VIRTUAL_HOST" environment variable to be recognized and routed by the vhost-proxy.
274+
if $vconfig['vhost_proxy']
275+
config.vm.provision "shell", run: "always", privileged: false do |s|
276+
s.inline = <<-SCRIPT
277+
echo "Starting system-wide HTTP reverse proxy bound to 192.168.10.10:80... "
278+
docker rm -f vhost-proxy > /dev/null 2>&1 || true
279+
docker run -d --name vhost-proxy -p 192.168.10.10:80:80 -p 192.168.10.10:443:443 -v /var/run/docker.sock:/tmp/docker.sock jwilder/nginx-proxy > /dev/null
280+
SCRIPT
281+
end
282+
end
283+
254284
# Automatically start containers if docker-compose.yml is present in the current directory.
255285
# See "autostart" property in vagrant.yml.
256286
if File.file?('./docker-compose.yml') && $vconfig['compose_autostart']
257287
config.vm.provision "shell", run: "always", privileged: false do |s|
258288
s.inline = <<-SCRIPT
289+
echo "Found docker-compose.yml in the root folder. Starting containers..."
259290
cd $1
260291
docker-compose up -d
261292
SCRIPT

presetup-mac.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# Console colors
4+
red='\033[0;31m'
5+
green='\033[0;32m'
6+
yellow='\033[1;33m'
7+
NC='\033[0m'
8+
9+
# Homebrew installation
10+
echo -e "${green}Installing Homebrew...${NC}"
11+
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
12+
13+
# Cask installation
14+
echo -e "${green}Installing Cask...${NC}"
15+
brew install caskroom/cask/brew-cask
16+
17+
# Update brew formulae
18+
echo -e "${green}Updating brew formulae...${NC}"
19+
brew update
20+
21+
# VirtualBox installation
22+
echo -e "${green}Installing virtualbox...${NC}"
23+
brew cask install virtualbox
24+
25+
# Vagrant installation
26+
echo -e "${green}Installing vagrant...${NC}"
27+
brew cask install vagrant
28+
29+
# Install docker
30+
echo -e "${green}Installing docker...${NC}"
31+
brew install docker
32+
33+
# Install docker-compose
34+
echo -e "${green}Installing docker-compose...${NC}"
35+
brew install docker-compose

presetup-win.cmd

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
REM Installation 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 Install git, virtualbox, vagrant, docker
5+
choco install git -y
6+
choco install virtualbox -y
7+
choco install vagrant -y
8+
choco install docker -y
9+
10+
REM Git configuration (proper line endings on Windows and support for long paths)
11+
git config --global core.autocrlf input
12+
git config --system core.longpaths true

setup.sh

+6-32
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,6 @@ green='\033[0;32m'
66
yellow='\033[1;33m'
77
NC='\033[0m'
88

9-
# Homebrew installation
10-
echo -e "${green}Installing Homebrew...${NC}"
11-
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
12-
13-
# Cask installation
14-
echo -e "${green}Installing Cask...${NC}"
15-
brew install caskroom/cask/brew-cask
16-
17-
# Update brew formulae
18-
echo -e "${green}Updating brew formulae...${NC}"
19-
brew update
20-
21-
# VirtualBox installation
22-
echo -e "${green}Installing virtualbox...${NC}"
23-
brew cask install virtualbox
24-
25-
# Vagrant installation
26-
echo -e "${green}Installing vagrant...${NC}"
27-
brew cask install vagrant
28-
29-
# Install docker
30-
echo -e "${green}Installing docker...${NC}"
31-
brew install docker
32-
33-
# Install docker-compose
34-
echo -e "${green}Installing docker-compose...${NC}"
35-
brew install docker-compose
36-
379
# Download Vagrantfile
3810
echo -e "${green}Downloading Vagrantfile into the current directory...${NC}"
3911
curl -sO https://raw.githubusercontent.com/blinkreaction/boot2docker-vagrant/master/Vagrantfile
@@ -51,26 +23,28 @@ SOURCE_FILE='';
5123
DOCKER_HOST_EXPORT='\n# Docker (default for Vagrant based boxes)\nexport DOCKER_HOST=tcp://localhost:2375\n'
5224

5325
# Detect shell to write to the right .rc file
54-
if [[ $SHELL == '/bin/bash' ]]; then SOURCE_FILE=".bashrc"; fi
26+
if [[ $SHELL == '/bin/bash' || $SHELL == '/bin/sh' ]]; then SOURCE_FILE=".bashrc"; fi
5527
if [[ $SHELL == '/bin/zsh' ]]; then SOURCE_FILE=".zshrc"; fi
5628

5729
if [[ $SOURCE_FILE ]]; then
5830
# See if we already did this and skip if so
59-
grep -Rq "export DOCKER_HOST=tcp://localhost:2375" $HOME/$SOURCE_FILE
31+
grep -q "export DOCKER_HOST=tcp://localhost:2375" $HOME/$SOURCE_FILE
6032
if [[ $? -ne 0 ]]; then
6133
echo -e "${green}Adding automatic DOCKER_HOST export to $HOME/$SOURCE_FILE${NC}"
6234
echo -e $DOCKER_HOST_EXPORT >> $HOME/$SOURCE_FILE
6335
fi
6436
# Source the file so we can use the DOCKER_HOST variabel right away.
65-
source $HOME/$SOURCE_FILE
37+
. $HOME/$SOURCE_FILE
6638
else
6739
echo -e "${red}Cannot detect your shell. Please manually add the following to your respective .rc or .profile file:${NC}"
6840
echo -e "$DOCKER_HOST_EXPORT"
6941
fi
7042

7143
# Check that Docker works
7244
echo -e "${green}Checking that everything is in place...${NC}"
73-
docker version
45+
docker version && vagrant ssh -c 'docker-compose --version'
7446
if [[ $? -ne 0 ]]; then
7547
echo -e "${red}Something went wrong. Please review console output for possible clues.${NC}"
48+
else
49+
echo -e "${green}Docker Host is up and running. Please restart your shell.${NC}"
7650
fi

vagrant.yml.dist

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ synced_folders:
1414
smb_password: 'vagrant'
1515
# List of folders to sync with rsync. These should be subfolder names within the <Projects> folder (e.g. "drupal7")
1616
# Uncomment and add folders per the example below as neccessary.
17+
# Note: you'll have to run `vagrant rsync-auto` in the background to keep the files in sync as you make changes
1718
folders:
1819
#- "projectA" # rsync projectA folder
1920
#- "projectB" # rsync projectB folder
@@ -35,3 +36,10 @@ hosts:
3536

3637
# Automatically start containers if docker-compose.yml is present in the current directory (default: false).
3738
compose_autostart: false
39+
40+
# vhost-proxy
41+
# https://github.com/jwilder/nginx-proxy
42+
# Use a reverse proxy to map host name to containers.
43+
# This is an alternative to using dedicated IP addresses in the 'hosts' section above.
44+
# Containers must define a "VIRTUAL_HOST" environment variable to be recognized and routed by the vhost-proxy.
45+
vhost_proxy: false

0 commit comments

Comments
 (0)