Skip to content

Instantly share code, notes, and snippets.

@Cobra16319
Last active February 29, 2024 12:42
Show Gist options
  • Save Cobra16319/9201f2d93bbfa9008b8655716111c956 to your computer and use it in GitHub Desktop.
Save Cobra16319/9201f2d93bbfa9008b8655716111c956 to your computer and use it in GitHub Desktop.
Run Vagrant on an M1 Mac Book with Docker

Here is a sample multi-provider Vagrantfile that can use either VirtualBox or Docker as a provider with vagrant:

$touch Vagrantfile

#Copy and paste Vagrantfile into newly created file

$vagrant up --provider=docker

Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.hostname = "ubuntu"
# Provider for VirtualBox
config.vm.provider :virtualbox do |vb|
vb.memory = "1024"
vb.cpus = 2
end
# Provider for Docker
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:ro"]
end
# Provision Docker Engine and pull down PostgreSQL
config.vm.provision :docker do |d|
d.pull_images "postgres:alpine"
d.run "postgres:alpine",
args: "-d -p 5432:5432 -e POSTGRES_PASSWORD=postgres"
end
end
@Cobra16319
Copy link
Author

*** Install Docker Compose on this Vagrant Machine *****

$ sudo apt-get -y install python3-pip
$ sudo pip install docker-compose
$ docker-compose --version

@bayeslearner
Copy link

Hi, I searched everywhere for an example and I found this piece. The documentation of vagrant says docker-compose is also supported, but I can't find any example. Do you happen to know how to use docker-compose (instead of docker) as provider and later provision the containers using either shell or ansible? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment