How to Install Docker on VirtualBox

Facebook
Twitter
LinkedIn

Never miss a post!

Sign up for our newsletter and get FREE Development Trends delivered directly to your inbox.

You can unsubscribe any time. Terms & Conditions.
Categories

Oracle VirtualBox is a cross platform virtualization application. It can be installed on any Intel or AMD-based computer, regardless of whether it is running Windows, Mac Linux, Solaris, or Linux. VirtualBox allows you to create and launch a virtual machine (guest) operating system in the window of your host operating system. Virtual machines allow you to test new software in a safe environment without causing any damage to your host operating system. And Docker is an open source technology that allows you to deploy applications using containers. Although it is still a new platform, Docker is continuously updated and has a large community of users. This guide will show you how to install ubuntu on VirtualBox and then install Docker on VirtualBox.

Before you follow the below steps, make sure you have VirtualBox installed on your system.

Install Ubuntu on VirtualBox

Create a new virtual machine

To create a virtual machine, open VirtualBox file and click New. Please fill in the required details:

  • Name: The Type and Version will automatically update if you include the word Ubuntu within your name.
  • Machine Folder: Here your virtual machines are stored, so that you can continue working on them whenever it suits you.
  • Type: Linux
  • Version: Ubuntu 64-bit

The next screen will allow you to choose how much RAM your main computer will give the virtual machine. To ensure that you are able to continue working outside the VM, keep your eyes on the green bar.

You can then choose how much of your hard drive your VM will use. Depending on whether VirtualBox is used with other VM software, the type of hard drive you choose will determine what kind. This is a VDI for now.

Next, you can select whether the hard drive is dynamically allocated (upto the limit that we will set on next screen), or filling up as required by the VM. We can also tell it to allocate all the memory from the beginning. This will increase performance but could take up space. It will be used as dynamically allocated in this tutorial.

You can also set the maximum memory that your VM can access. Click Next to initiate the machine.

 

Install your image

To launch the virtual machine, click Start. The prompt will appear to choose the start-up disc. Click the file icon to open optical disc selector. Then click Add to locate your .iso file.

Select the disc image that you wish to use and then click Start in the start-up disc window. Ubuntu desktop should now start and display the installation menu. You can then follow the steps on the screen to install Ubuntu Desktop.

 

Installing Guest Additions

VirtualBox’s Guest Additions adds an additional piece of software to unlock some of the more advanced features. This allows for better integration between the virtual machine and the host computer, as well as enhanced video support that allows you to choose from a variety of display resolutions when using VMSVGA.

You will need to finish your Ubuntu installation on your virtual machine before you can install Guest Additions.

Select Devices > Insert Guest Additional CD from there.

You will be prompted to download the Guest Additions disk file. Click on Download. Next, click Insert.

You will see the disc on your virtual desktop. Then, you will be asked to run it. To install it, enter your password. After this process is completed, restart your virtual machine to allow the new features to take place.

 

Close the machine, but before you start it up again, return to the Settings menu and change the Graphics Controller back to VMSVGA and Enable 3D Acceleration. This will improve the performance of your virtual machine by taking advantage of your PC’s 3D hardware and allow you to resize your desktop resolution!

 

Install Ubuntu on VirtualBox

Follow below steps to install Ubuntu on VirtualBox.

Step 1: Update your local database

Before installing, update the packages list.

sudo apt update

Step 2: Install dependencies to support https

Install packages that allow you to upload files from https

sudo apt install apt-transport-https ca-certificates curl software-properties-common

This is how each command works.

  • apt-transport-https allows you to send files and data via https
  • Ca-certificates: Use your computer or web browser to verify security certificates
  • Curl: A file transfer tool
  • software-properties-common: adds software management scripts

 

Step 3: Add Docker’s GPG Key

Next, add the GPG Key – security feature that verifies installation files are authentic.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –

Step 4: Install the Docker Repository

In this step, use the command below to add the Docker repository to the apt sources.

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"

Step 5: Update Repositories

Update the database with the Docker packages from the repo you have just added

sudo apt update

Run the command to ensure that the installation is running from the official Docker repository.

apt-cache policy docker-ce

This should give the following output:

Output of apt-cache policy docker-ce

docker-ce:
Installed: (none)
Candidate: 5:19.03.5~3-0~ubuntu-bionic
Version table:
5:19.03.5~3-0~ubuntu-bionic 500
500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
5:19.03.4~3-0~ubuntu-bionic 500
500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
5:19.03.3~3-0~ubuntu-bionic 500

You will see that docker-ce has not been installed from the output. The output will display the target operating system as well as the version number for Docker. Version numbers can vary depending on when the Docker was installed.

 

Step 6: Install the latest version of Docker

After confirmation, you can use the following command for Docker installation.

sudo apt install docker-ce

This will install Docker and start the daemon, enabling it to start automatically on boot. Run this command to confirm that Docker is running.

sudo systemctl status docker

The following output will be generated if the command is installed and runs successfully

$ sudo systemctl status docker
  • docker.service – Docker Application Container Engine

Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: e

Active: active (running) since Fri 2022-08-26 07:46:40 UTC; 50s ago

Docs: https://docs.docker.com

Main PID: 2071 (dockerd)

Tasks: 8

CGroup: /system.slice/docker.service

└─2071 /usr/bin/dockerd -H fd:// –containerd=/run/containerd/contain

 

This part of the output shows that the installation was successful, and that Docker is active and running.

Final Thoughts

In this post we have learned to install docker on VirtualBox. Firstly, we installed ubuntu desktop on a VirtualBox. And then we installed docker on a ubuntu VirtualBox. Go ahead and follow the steps to install docker on VirtualBox.

Facebook
Twitter
LinkedIn

Our website uses cookies that help it to function, allow us to analyze how you interact with it, and help us to improve its performance. By using our website you agree by our Terms and Conditions and Privacy Policy.