Skip to content

Instantly share code, notes, and snippets.

@aharden
Forked from glenfant/Vagrantfile
Last active May 26, 2020 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aharden/790ae1e46291822a9c14463fabd6c57e to your computer and use it in GitHub Desktop.
Save aharden/790ae1e46291822a9c14463fabd6c57e to your computer and use it in GitHub Desktop.
A Vagrantfile for MacOS or Windows host, making an Ububtu 20.04 playground for the latest Docker and Docker-compose.
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# Reference: https://gist.githubusercontent.com/glenfant/7772f48aa17eb4e09d4a62390825eade/raw/b7284e30c3ba3a6ba9e03bb37abb65eb193842f7/Vagrantfile
# 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 latest 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 \
apt-transport-https \
python3-pip > /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-20.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