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.

VirtualBox:

vagrant box add generic/alpine38 --provider=virtualbox

KVM:

vagrant box add generic/alpine38 --provider=libvirt

Parallels:

vagrant box add generic/alpine38 --provider=parallels

VMware:

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

$39.95
$19.45  in stock
28 new from $19.45
19 used from $14.99
Free shipping
Buy Now
Amazon.com
as of July 8, 2020 11:12 am

Features

Part Number54410657
Release Date2019-03-07T00:00:01Z
Edition2
LanguageEnglish
Number Of Pages504
Publication Date2019-03-07T00:00:01Z

Linux Command Line and Shell Scripting Bible

$50.00
$31.49  in stock
13 new from $31.49
21 used from $24.41
Free shipping
Buy Now
Amazon.com
as of July 8, 2020 11:12 am

Features

  • Wiley

Bash Pocket Reference: Help for Power Users and Sys Admins

$19.99
$10.98  in stock
18 new from $10.98
15 used from $6.32
Buy Now
Amazon.com
as of July 8, 2020 11:12 am

Features

  • O REILLY

LEAVE A REPLY

Please enter your comment!
Please enter your name here

14 + 8 =