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:

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

Paste into a Vagrantfile:

Then:

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!).

Vagrant: Provisioning

Provisioning a VM with your Vagrantfile.

e.g. to install dockercreate a file bootstrap.sh :

It’s a little convoluted. Why didn’t I use config.vm.provision "docker"? ‘cos it didn’t work for me: https://stackoverflow.com/questions/52498892/install-docker-via-a-vagrantfile

Note: don’t use apt-get install -y docker as this installs the System tray!

https://gist.github.com/kjellski/6158747 and https://unix.stackexchange.com/questions/363048/unable-to-locate-package-docker-ce-on-a-64bit-ubuntu/363058#363058

and add it to your Vagrantfile, e.g.:

and force Vagrant to reprovision with:

vagrant reload --provision

https://www.vagrantup.com/intro/getting-started/provisioning.html

https://www.vagrantup.com/docs/vagrantfile/machine_settings.html