How to run old code - an introduction to virtualization
As a consultancy specializing in upgrades, dealing with legacy code is our bread and butter. Incompatible versions of Ruby, different version managers, C errors while running
bundle install - there are many ways that setting up projects is not always straightforward. Add to this several projects and your development machine becomes a mess of hard to diagnose issues due to mismatched system dependencies. Virtualization to the rescue!
Virtualization software uses the resources available from the main machine to create separate instances on which we can install other operating systems. There are two different types of virtualization software that are in use: virtual machines and containerization software. These types of software differ in how much of the operating system they virtualize.
This article attempts to explain the difference between virtual machines and containers to developers who are new to virtualization software, and gives three options to explore if you’d like to use virtualization for your next project.
Virtual machines virtualize the whole operating system. A virtual machine is created by using virtualization software that essentially mimics the bare metal. This software (the host) controls the physical resources available to all virtual machines. You can then install and run one or more operating systems (the guest, or the virtual machine in this case) on top of the virtualization software. Each virtual machine is individually responsible for maintaining its’ own system resources, and one machine’s resources are not available to another.
Pro: Virtual machines run a complete operating system, so they have access to all operating system features, including system libraries and binaries.
Cons: Since the whole operating system is running, you are responsible for system maintenance, including security updates. It can also be inefficient to run virtual machines because they use a lot of resources.
Containers combine three parts of the Linux kernel together with resources from the host OS to create and run separate processes from the OS. These parts are chroot, namespaces, and cgroups:
- chroot: this sets the root directory of a new process. This process has no visibility outside of that root directory.
- namespaces: allow you to hide processes from other processes. This protects containers from other containers.
- cgroups: allow you to maintain your own resources. This ensures one container’s resources don’t affect any others.
Pros: Containers don’t take up as many resources as virtual machines since they are not emulating an entire OS. There are fewer security and maintenance concerns.
Cons: Containers share libraries and binaries with the host OS.
Options for virtualization software
Want to try running virtualization software to set up your next project? There are several different options you can try:
Building your own images from ISOs and virtualization software
If you want to go the virtual machine route, you can use virtualization software such as VMWare and VirtualBox to create virtual machines using ISOs of the operating system of your choice. VMWare has software for Windows and Linux to run a single virtual machine for personal use. VirtualBox also supports Windows and Linux, as well as Mac OS X and Solaris.
Here’s a rough outline of the steps that you will need to take to create a virtual machine:
- Download virtualization software.
- Get an ISO of your operating system.
- Create a new machine. There will be several screens to go through that allow you to set your memory size, add your virtual hard disk, choose whether your virtual hard disk is dynamically allocated (grows as it is used) or fixed sized, and choose the size of the virtual hard disk.
- Once that is done, click on your virtual machine in the menu and click on the green arrow in the top tab that says “Start”.
- You will get a prompt that asks you to select a virtual optical disk file. This is where you can select your OS’s ISO.
- You can now use your virtual machine.
To start using Docker, you will need to install
docker and create a
Dockerfile: file that is used to create a Docker image
docker: creates the docker image from the
To save time, you can use a base image to set up a container. We have a guide on how to do that here: Creating a Legacy Rails Container .
While not essential, I have always found it easier to run containers using
docker-compose. To use
docker-compose, you will have to create a
docker-compose.yml file that describes how to run the Docker container.
If the first two options sound too complicated, and you don’t mind using a Linux OS as your base operating system, try running Multipass. Multipass is a product by Canonical (the makers of Ubuntu). It creates a ready to run Ubuntu virtual machine.
To start using Multipass, install it either by using the installer package or using brew .
On the Install page , there are a few commands listed. The two I use the most are:
multipass launch --name foo, where
foois the name of your instance: this creates a new instance
multipass exec foo -- /bin/bash: this starts your instance and launches a bash shell. From here you can start your project, cloning it with git, which is already installed, installing your development dependencies, etc.
Try running your next project inside virtualization software. You might find that virtualization becomes an indispensable part of your development workflow.