Last active
May 26, 2020 17:14
-
-
Save glenfant/7772f48aa17eb4e09d4a62390825eade to your computer and use it in GitHub Desktop.
A Vagrantfile for MacOS or Windows host, making an Ububtu 16.04 playground for the latest Docker (17.03-ce) and Docker-compose 1.12.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# | |
# Docker playground for MacOS and Windows | |
# ======================================= | |
# | |
# - Installs the latest Docker + Docker-compose | |
# - Uses faster NFS files sync on Mac OS | |
# - Uses faster SMB files share on Windows | |
# | |
# Installation steps: | |
# | |
# - Install lates Virtualbox and its guest extensions pack | |
# https://www.virtualbox.org/wiki/Downloads | |
# - Install Vagrant | |
# https://www.vagrantup.com/ | |
# - cd /where/you/want | |
# - cp Vagrantfile . | |
# - vagrant up | |
# (you will be prompted for your sudo password when vagrant tunes nfs config) | |
# - vagrant ssh | |
# | |
# Quick check the installation in a shell of the guest Ubuntu VM: | |
# | |
# - docker run hello-world | |
# ------------------------------- | |
module OS | |
def OS.macos? | |
(/darwin/ =~ RbConfig::CONFIG['host_os']) != nil | |
end | |
def OS.windows? | |
File::SEPARATOR == '\\' | |
end | |
def OS.unix? | |
!OS.windows? | |
end | |
# Lazy guess, it could be a xBSD | |
def OS.linux? | |
OS.unix? and not OS.macos? | |
end | |
end | |
# Docker stuff provisioning shell scripts | |
USER = 'vagrant' | |
# Read https://docs.docker.com/engine/installation/linux/ubuntu/ | |
# for more options | |
DOCKER_INSTALL_LATEST = <<-END_SCRIPT | |
sudo apt-get update | |
echo "Installing base software" | |
sudo apt-get -y install \ | |
nfs-common \ | |
python-software-properties \ | |
apt-transport-https \ | |
ca-certificates \ | |
curl \ | |
python3-pip \ | |
software-properties-common > /dev/null 2>&1 | |
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-get update | |
echo "Installing Docker bundle" | |
sudo apt-get -y install docker-ce > /dev/null 2>&1 | |
sudo usermod -a -G docker #{USER} | |
echo "Installing Docker-compose" | |
sudo pip3 install -U pip | |
sudo pip3 install docker-compose | |
END_SCRIPT | |
Vagrant.configure("2") do |config| | |
config.vm.box = "bento/ubuntu-16.04" | |
if OS.unix? | |
config.vm.network "private_network", type: "dhcp" | |
config.vm.synced_folder ".", "/vagrant", type: "nfs" | |
else | |
# OS.windows? -> true | |
config.vm.synced_folder ".", "/vagrant", type: "smb" | |
end | |
config.vm.provider "virtualbox" do |vb| | |
vb.memory = "2048" | |
end | |
config.vm.provision "shell", inline: DOCKER_INSTALL_LATEST | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment