If you are using fairly recent Vagrant with Docker provisioner support (e.g. the steps below were tested using 2.2.6), then you can install Docker with a very simple one or two one-liners, without the d.run or similar hacks:
Vagrant.configure(2) do |config|
config.vm.box = "generic/ubuntu1904"
# Install Docker
config.vm.provision :docker
# Install Docker Compose
# First, install required plugin https://github.com/leighmcculloch/vagrant-docker-compose:
# vagrant plugin install vagrant-docker-compose
config.vm.provision :docker_compose
end
Run vagrant provision
or vagrant up
and observe this output:
==> default: Running provisioner: docker...
default: Installing Docker onto machine...
==> default: Running provisioner: docker_compose...
default: Checking for Docker Compose installation...
default: Getting machine and kernel name from guest machine...
default: Downloading Docker Compose 1.24.1 for Linux x86_64
default: Uploading Docker Compose 1.24.1 to guest machine...
default: Installing Docker Compose 1.24.1 in guest machine...
default: Symlinking Docker Compose 1.24.1 in guest machine...
Finally, vagrant ssh
to the VM and check versions of the deployed Docker infrastructure:
$ docker --version
Client: Docker Engine - Community
Version: 19.03.3
API version: 1.40
Go version: go1.12.10
Git commit: a872fc2f86
Built: Tue Oct 8 01:00:44 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.3
API version: 1.40 (minimum version 1.12)
Go version: go1.12.10
Git commit: a872fc2f86
Built: Tue Oct 8 00:59:17 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.10
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.0-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.0
GitCommit: fec3683
--provision
would take similarly long time, I added:run => 'always'
egconfig.vm.provision :docker, :run => 'always'
to force the docker provisioning to run. – Haldis