Vagrant is a tool created to enable users create and configure lightweight, reproducible, and portable development environments with the operating system of their choice. Vagrant works with various virtualization technologies such as VirtualBox, VMware, KVM, Parallels and Hyper-V. In this guide we will look at how you can quickly run an Alpine Linux virtual machine with Vagrant.
Alpine Linux is a community developed operating system designed with security in mind for use in IoT devices, networking routers, VPN solutions, firewall devices, VoIP systems and on commodity servers. The operating system is so lightweight that it can run on most small form factor devices efficiently.
Before you can run Alpine Linux with Vagrant, ensure you’ve installed Vagrant on your system. The following commands can be used for reference.
Install Vagrant on Ubuntu / Debian
sudo apt update sudo apt install vagrant
Install Vagrant on Fedora:
sudo dnf install vagrant
You Virtualization technology of choice should also be installed and configured.
Add Alpine Linux Vagrant Box
Add Alpine Linux Box to your local system. In Vagrant terminologies, Boxes are the package format for Vagrant environments.
vagrant box add generic/alpine38 --provider=virtualbox
vagrant box add generic/alpine38 --provider=libvirt
vagrant box add generic/alpine38 --provider=parallels
vagrant box add generic/alpine38 --provider=vmware_desktop
Sample output for box addition:
................... ==> box: Loading metadata for box 'generic/alpine38' (eval):3: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call /usr/share/vagrant/gems/gems/vagrant-2.2.6/lib/vagrant/ui.rb:223: warning: The called method `say' is defined here box: URL: https://vagrantcloud.com/generic/alpine38 ==> box: Adding box 'generic/alpine38' (v3.0.6) for provider: libvirt box: Downloading: https://vagrantcloud.com/generic/boxes/alpine38/versions/3.0.6/providers/libvirt.box (eval):3: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call /usr/share/vagrant/gems/gems/vagrant-2.2.6/lib/vagrant/ui.rb:223: warning: The called method `say' is defined here box: Download redirected to host: vagrantcloud-files-production.s3.amazonaws.com box: Calculating and comparing box checksum... (eval):3: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call /usr/share/vagrant/gems/gems/vagrant-2.2.6/lib/vagrant/ui.rb:223: warning: The called method `say' is defined here ==> box: Successfully added box 'generic/alpine38' (v3.0.6) for 'libvirt'!
View available boxes:
$ vagrant box list centos/7 (libvirt, 1905.1) centos/8 (libvirt, 1905.1) cloudnatives/amazon-linux-2 (libvirt, 1.0.0) eurolinux-vagrant/oracle-linux-8 (libvirt, 8.1.2) fedora/31-cloud-base (libvirt, 31.20191023.0) fedora/32-beta-cloud-base (libvirt, 32.20200312.0) generic/alpine38 (libvirt, 3.0.6)
Run Alpine Linux with Vagrant
Create a Vagrantfile – Refer to Vagrant Providers for any specific provider.
This specific to libvirt provider.
$ vim Vagrantfile # -*- mode: ruby -*- # vi: set ft=ruby : ENV['VAGRANT_DEFAULT_PROVIDER'] = 'libvirt' Vagrant.configure("2") do |config| config.vm.define "alpine" do |config| config.vm.hostname = "myalpine" config.vm.box = "generic/alpine38" config.vm.box_check_update = false config.vm.provider :libvirt do |v| v.memory = 1024 v.cpus = 1 end end end
You may need to adjust it for VirtualBox, VMware, Parallels and any other provider.
Start the virtual machine when done by using the command below.
$ vagrant up
Once the machine is up, you can ssh with the command:
$ vagrant ssh myalpine:~$ cat /etc/os-release NAME="Alpine Linux" ID=alpine VERSION_ID=3.8.5 PRETTY_NAME="Alpine Linux v3.8" HOME_URL="http://alpinelinux.org" BUG_REPORT_URL="http://bugs.alpinelinux.org"
Update the system.
$ sudo apk update fetch https://sjc.edge.kernel.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz fetch https://sjc.edge.kernel.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz v3.8.5-50-g73a848a2b6 [https://sjc.edge.kernel.org/alpine/v3.8/main] v3.8.5-37-gf06ffe835a [https://sjc.edge.kernel.org/alpine/v3.8/community] OK: 9563 distinct packages available
Try package installation:
$ sudo apk add vim OK: 147 MiB in 80 packages myalpine:~$ sudo apk add bash-completion (1/3) Installing bash-completion (2.8-r0) (2/3) Installing kmod-bash-completion (24-r1) (3/3) Installing glib-bash-completion (2.56.1-r1) OK: 149 MiB in 83 packages
If you want to use ssh to access the VM from any directory, generate ssh configuration and save it.
$ vagrant ssh-config >> ~/.ssh/config
You can then ssh with the command:
$ ssh alpine myalpine:~$
Expect more guides from us on Vagrant. In the meantime, check:
Books to check out:
The Linux Command Line, 2nd Edition: A Complete Introduction
$19.49 in stock
24 used from $15.52
|Number Of Pages||504|
Linux Command Line and Shell Scripting Bible
$45.00 in stock
26 used from $19.43
Bash Pocket Reference: Help for Power Users and Sys Admins
$13.00 in stock
16 used from $8.96
- O REILLY