Install Docker via a Vagrantfile

Tons of ways of doing this on the internet – many that don’t work for various reasons – e.g. older versions of Ubuntu, etc… – and ranging from complex to very complex.

Here’s two simple ways:

  1. Most simple

Paste into a Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  config.vm.define "vm1"
  config.vm.provision "docker" 
end
vagrant up 
vagrant ssh vm1
docker version

2. A little more manual using Docker’s convenience script:

Paste into a Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  config.vm.define "vm1"
end

Then:

vagrant up
vagrant ssh vm1
sudo su
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh

Here’s what didn’t work for me:

https://stackoverflow.com/questions/52498892/install-docker-via-a-vagrantfile

I guess it doesn’t help that precise64┬áis quite an old version of Ubuntu but it’s what was given on the Vagrant website for provisioning Docker.

and

https://www.vagrantup.com/docs/provisioning/docker.html

which I basically ignored ‘cos it didn’t have a correct concrete example as of the time of writing this blog post (even though it’s Hashicorp’s own website!).

Leave a Reply

Your email address will not be published. Required fields are marked *