Ubuntu image for use as a Docker provider in Vagrant
10K+
This images can be used as a provider for Vagrant as a development environment.
This was inspired by Apple's introduction of the M1 chip which is ARM based. That means that solutions which use Vagrant and VirtualBox will not work on Apple M1 because VirtualBox requires an Intel processors. This lead me to find a solution for a virtual development environment that works with ARM and thus Apple M1 computers. You can find out more information about why I built it here:
Developing on Apple M1 Silicon with Virtual Environments
Docker has introduced Docker Desktop for Apple silicon that runs Docker on Macs that have the Apple M1 chip. By using Docker as a provisioner for Vagrant, we can simulate the same experience as developers using Vagrant with VirtualBox. This is one case where you actually do want a Docker container to behave like a VM.
The ubuntu image is based on Ubuntu 21.04 and the debian image is Debian 11. Both contain the packages that are needed for a valid vagrant box. This includes the vagrant userid with password-less sudo privileges. It also contains as sshd server. Normally, it is considered a bad idea to run an ssh daemon in a Docker container but in this case, the Docker container is emulating a Virtual Machine (VM) to provide a development environment so it makes perfect sense. ;-)
Here is a sample Vagrantfile that uses this image:
Vagrant.configure("2") do |config|
config.vm.hostname = "ubuntu"
config.vm.provider :docker do |docker, override|
override.vm.box = nil
docker.image = "rofrano/vagrant-provider:ubuntu"
docker.remains_running = true
docker.has_ssh = true
docker.privileged = true
docker.volumes = ["/sys/fs/cgroup:/sys/fs/cgroup:rw"]
docker.create_args = ["--cgroupns=host"]
# Uncomment to force arm64 for testing images
#docker.create_args = ['--platform=linux/arm64']
end
end
You can omit the docker.privileged flag if you won't be running Docker inside the container but since I use these containers like VMs, I run Docker inside of them. If you want to test the ARM version on an Intel computer just uncomment the docker.create_args line which adds --platform=linux/arm64 to the docker run command to force the aarch64 image to be used.
To use this provider, add the --provider flag to your vagrant command:
vagrant up --provider=docker
This will use this the docker image specified in your Vagrantfile as the base box.
To build this image you must use buildx and build it for multiple architectures so that it can run on both Intel and ARM machines.
If you don't have a builder you must first create one:
% export DOCKER_BUILDKIT=1
% docker buildx create --use --name=qemu
qemu
% docker buildx inspect --bootstrap
Then you can build the multi-platform image like this:
docker buildx build -t rofrano/vagrant:ubuntu --platform=linux/amd64,linux/arm64 --push .
This will use QEMU to build a multi-platform image and push it to docker hub.
Content type
Image
Digest
Size
84.9 MB
Last updated
over 4 years ago
docker pull rofrano/vagrant-provider:focal