This is a guide to how to use Vagrant to virtual some OS, like Linux/Windows/MacOS etc.
Introduction
Simple and Powerful
HashiCorp Vagrant provides the same, easy workflow regardless of your role as a developer, operator, or designer. It leverages a declarative configuration file which describes all your software requirements, packages, operating system configuration, users, and more.
Works where you work
Vagrant works on Mac, Linux, Windows, and more. Remote development environments force users to give up their favorite editors and programs. Vagrant works on your local system with the tools you’re already familiar with. Easily code in your favorite text editor, edit images in your favorite manipulation program, and debug using your favorite tools, all from the comfort of your local laptop.
Installation
vagrant+docker
Recommanding by vagrant plus docker:
https://www.vagrantup.com/docs/providers/docker
1 | curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - |
vagrant+virtualbox
1 | #https://www.vagrantup.com/downloads |
Configuration
vagrant+docker
Dockerfile:
1 | #Version: 1.0.0 |
docker-entrypoint.sh:1
2
3
4
# run the command given as arguments from CMD
exec "$@"
script.sh: Finding the details from belows.
Building docker image:
1 | docker build -t dave/ubuntu:22.04 . |
Vagrangfile:
1 | # -*- mode: ruby -*- |
Or just using docker by itself:
1 | #https://www.cnblogs.com/bakari/p/10893589.html |
Or multiple nodes with Vagrantfile:
1 | # -*- mode: ruby -*- |
Installing docker in dokcer:
docker.sh:
1 |
|
Starting:
1 | vagrant up |
Entering the container:
1 | vagrant docker-exec -it -- /bin/bash |
vagrant+virtualbox
How to get the box images?
Search from https://app.vagrantup.com/boxes/search to get a certain box, like “ubuntu 22.04”, going to the details you can get the following command:
1 | vagrant init generic/ubuntu2004 |
Just running the command above, you will see the box url. Since the internet connection is very slow in China, you can interrupt the operation when you get the final download url.
1 | #Centos |
Ubuntu
Adding box:
1 | sudo vagrant box add ubuntu22.04 box/ubuntu-22.04.box |
Vagrantfile:
1 | # -*- mode: ruby -*- |
script.sh
1 |
|
Starting:
1 | vagrant up |
CentOS
Adding box:
1 | sudo vagrant box add centos7 box/CentOS-7-x86_64-Vagrant-2004_01.VirtualBox.box |
Vagrantfile
1 | # -*- mode: ruby -*- |
script.sh
1 |
|
Starting:
1 | vagrant up |
Windows10
Adding box:
1 | sudo vagrant box add win10 box/win10.box |
Vagrantfile
1 | # -*- mode: ruby -*- |
Starting:
1 | vagrant up |
MacOS
It doesn’t work, reslove it later.
Adding box:
1 | sudo vagrant box add macos box/macos-10.15.box |
Vagrantfile
1 | # -*- mode: ruby -*- |
Starting:
1 | vagrant up |
Command Usage
1 | #cd vagrant |
Modifying the directory of VirtualBox:
1 | #Using root to handle: |
Resize Disk:
1 | vagrant plugin install vagrant-disksize |
Note: this will not work with vagrant reload
Nvidia Docker
1 | https://github.com/NVIDIA/nvidia-docker/issues/1034 |
vim Vagrantfile:
1 | # -*- mode: ruby -*- |