How to Install Docker on Ubuntu

In this blog post, I will explain the step-by-step process for installing Docker on an Ubuntu Linux system. As a reference for you, here are the official instructions.

At the end, I will explain in detail how Docker is used in robotics.

Uninstall Old Versions of Docker

The first thing you need to do is to uninstall any outdated versions of Docker that might be lurking on your computer.

Open a terminal window, and type the following command:

for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done

You might get a message back saying that you have none of those packages installed. That is just fine.

Set Up the Apt Repository

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

Install Docker

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Verify that Docker Installed

sudo service docker start
sudo docker run hello-world

Post-Installation Configuration

Here are some recommended steps to take after you have successfully installed Docker.

Create the docker group.

sudo groupadd docker

Add your user to the docker group.

sudo usermod -aG docker $USER

Reboot your computer.

sudo reboot

Or you could have activated changes to groups instead of rebooting:

newgrp docker

To test that you can run Docker without using “sudo”, type the following command:

docker run hello-world

Now configure Docker to start on boot:

sudo systemctl enable docker.service
sudo systemctl enable containerd.service

You can stop this startup on boot at any time, by typing:

sudo systemctl disable docker.service
sudo systemctl disable containerd.service

Now you’re all set.

How is Docker Used in Robotics?

Docker is a toll that allows you to package your software, including all its dependencies, into a standalone unit called a “container.” You can then deploy this container on any machine that has Docker installed, regardless of the underlying computer that is being used.

Docker is used in robotics for a number of reasons, including:

  • Reproducibility: Docker containers allow you to create a reproducible development environment for your robotics project. This means that you can be confident that your project will run the same way on any machine that has Docker installed.
  • Portability: Docker containers are portable, meaning that they can be easily moved from one machine to another. This is useful for developing and deploying robotics applications on a variety of platforms, including embedded devices, cloud servers, and robots.
  • Scalability: Docker containers are lightweight and efficient, making them ideal for scaling robotics applications. You can easily start and stop multiple containers on a single machine, or deploy multiple containers across a cluster of machines.

Here are some specific examples of how Docker is used in robotics:

  • Developing and testing robotics software: Docker can be used to create isolated development environments for robotics software. This allows developers to work on different components of a robotics project in parallel, without worrying about conflicts with other dependencies. Docker can also be used to test robotics software on different platforms, without having to install all of the necessary dependencies on each platform.
  • Deploying robotics applications: Docker can be used to deploy robotics applications on a variety of platforms, including embedded devices, cloud servers, and robots. This makes it easy to scale robotics applications and deploy them to production environments.
  • Running ROS 2: Docker is often used to run ROS 2. You can find the official ROS 2 Docker repository here on DockerHub.

If you are looking to simplify your development and deployment of software on to robots, I highly recommend you learn Docker.

That’s it. Keep building!

How to Install Ubuntu and VirtualBox on a Windows PC

In this project, we will get started on our Robot Operating System (ROS) programming journey by installing Ubuntu. Ubuntu is a popular distribution (i.e. flavor) of the Linux operating system and is fully supported by ROS, the most popular framework for writing robotics software. If you have a Windows PC (I have Windows 11), I recommend you install a VirtualBox first and then install Ubuntu in the Virtual Box. I’ll show you how to do all that below.

The process for installing Ubuntu has a lot of steps, so hold on tight, don’t give up if something goes wrong, and go slowly so that you get your installation setup properly. Let’s get started!

Requirements

Here are the project requirements:

  • Install Ubuntu
  • Install Virtual Box
  • Install Ubuntu on VirtualBox
  • Learn Important Linux Terminal Commands

You Will Need

The following components are used in this project. You will need:

Directions

Download the Ubuntu Image

Check Ubuntu Releases to find the latest version of Ubuntu that has long term support (LTS). As of this writing, the latest release is Ubuntu 22.04 LTS (Jammy Jellyfish). You can download 22.04 if you want, but I will download Ubuntu 20.04 (Focal Fossa) since I need it for my ROS 2 Galactic work.

ubuntu_releases_2022

Click on the latest release of Ubuntu, and download the 64-bit PC (AMD64) desktop image (.iso file). The download process will take a while since it is a large file.

Before installing Ubuntu, you need to install Virtual Box. Virtual Box extends the capabilities of your host computer (i.e. your laptop or desktop PC) by enabling you to install and run an operating system in a new environment on top of your current operating system (Windows 11 in my case). The environment the new operating system will run in is known as a virtual machine (or guest).

Install VirtualBox

Let’s download VirtualBox. Go to VirtualBox downloads.

Select the platform package for Windows hosts to download the executable (.exe) file.

virtual_box

Detailed installation instructions for all operating systems (Windows, Mac OS, Linux, and Solaris) can be found in the instruction manual. Let’s go through the steps.

Double-click on the executable file.

setup_wizard_vbox

Click Next to begin the installation process.

Click Next to install the VirtualBox in the default location.

1-virtual-box-default-location

Click Next to choose the default features.

2-keep-everything-as-default

You will see a warning about network interfaces. Ignore it, and click Yes to proceed.

3-ignore-warning

You are now ready to install VirtualBox. Click Install to proceed.

4-ready-to-install

Click Finish to run VirtualBox.

5-click-finish

You can optionally delete the original executable file for VirtualBox (the one with the .exe extension). You don’t need it anymore.

Create a Virtual Machine

Now that VirtualBox is installed on your computer, we need to now create a new virtual machine.

Click the New button in the toolbar.

10-start-virtual-boxJPG

Type in a descriptive name for your operating system. You can stick with the default machine folder. The machine folder is where your virtual machines will be stored.

Also, select the operating system that you want to later install (Linux in this case).

12-virtualbox-name-operating-systemJPG

Click Next to proceed.

The default memory size for me is 1024 MB. That is not enough. Raise it to 6470 MB, and then click Next to proceed.

13-select-recommended-ramJPG

Make sure “Create a virtual hard disk now” is selected, and click Create.

14-create-virtual-hard-diskJPG

Select “VirtualBox Disk Image (VDI)”, and click Next.

Choose a Fixed size virtual hard disk so that you have better performance, and click next.

15-fixed-sizeJPG

You can stick with the default hard disk space (10GB as of the time of this writing) or go with something like 50 GB. I went with 50 GB. I also prefer to save my hard disk on my D drive (which has more space than my C drive). Then click Create.

16-default-hard-disk-sizeJPG
17-creating-virtual-diskJPG

Double-click on the left panel where it says “Ubuntu 18.04.” A startup window will appear.

18-new-virtual-machineJPG

Click the Folder icon next to Empty and select the Ubuntu image you downloaded earlier in this tutorial. It is a .iso file. You can make sure that your .iso file is somewhere in your C drive (doesn’t have to be on your Desktop). Then click Start to proceed.

19-startup-windowJPG

You might get an error that looks like this.

20-errorJPG

Click Close VM.

Enable Virtualization Technology on Your Computer

The error above arises because virtualization technology is disabled on your computer by default. We need to enable it. Let’s do that now.

Go down to the search area on your computer in the bottom left of your screen, and searched for “Advanced Startup”.

21-searchJPG

Click “Change Advanced Startup Options.”

Click Restart Now.

Click Troubleshoot.

Click Advanced Options.

Click UEFI Firmware Settings.

Click Restart to change the UEFI Firmware Settings.

Click F10 BIOS Setup.

Press the right arrow to go to System Configuration.

Scroll down to Virtualization Technology.

Press Enter to select Enabled.

Press the down arrow and then Enter to select Enabled.

Press F10 to save and exit.

Press Enter on Yes to save the changes.

Your computer will reboot.

Double-click on the VirtualBox icon to start it.

Click on the left panel of the window to start the Ubuntu virtual machine. Or you can just click Start in the toolbar.

22-restart-virtual-boxJPG

You should see the Ubuntu window appear.

Install Ubuntu

Click on “Install Ubuntu” to install Ubuntu.

23-ubuntu-startJPG

Click “Continue” to save the keyboard layout. The default English one is fine.

Keep clicking Continue through all the prompts. The options you want selected as you go through the prompts are the following:

  • Download updates while installing Ubuntu
  • Erase disk and install Ubuntu

You will get to a point where you will need to set your time zone. It will be a big map of the world that should automatically detect your location.

Type in a computer name and pick a username and password. I select the “Log in automatically” option.

When installation is complete, click “Restart Now.”

If you get a message that says “Please remove the installation medium. Then press ENTER,” just press ENTER.

When you reboot, you will go to the Ubuntu desktop.

25-welcome-to-ubuntuJPG

If at any time you want to exit Ubuntu, go to File → Close. You will be given the option to save your machine state so that you can pick up where you left off the next time you login to Ubuntu.

27-save-machine-stateJPG

Two additional notes….when you power up your VirtualBox, it is a good idea to go to Settings → Display and change your Video Memory to 128 MB. This will give you ample video memory.

32-video-memoryJPG

Also go to Settings → System → Processor, and adjust the number of CPUs to 4.

33-number-of-cpusJPG

If you at any point in the future run out of hard drive space for your virtual machine, you can move it to another drive (e.g. D drive) by following this article at Tech Republic.

Here are the complete settings on my Windows machine.

34-my-settingsJPG

Getting Used to Ubuntu

Similar to the C drive in Windows 10, Linux has a file system (everything branches from the / symbol). You can find it by clicking the icon of the file cabinet on the right side of the desktop. It is the third icon down in the image below.

28-file-cabinetJPG

Click “Other Locations.”

29-other-locationsJPG

Click “Computer.”

You will see all the files. For example, the path to the bin file is /bin 

30-ubuntu-file-managerJPG

You can find popular software applications for download in the Ubuntu Software module. It is the sixth icon in the left-hand panel. 

31-ubuntu-softwareJPG

Linux Terminal Commands With the Ubuntu Command-Line Interface

We could certainly navigate around Ubuntu using the graphical user interface, but we would miss out on being able to run advanced processes for ROS. This is where the Terminal application comes in handy. The Terminal application is the Ubuntu command-line interface and is similar to the Command Prompt on a Windows 10 system. It enables us to use Linux terminal commands.

To open the Terminal, click the bottom left where you see those nine white dots and search for “Terminal” at the top. 

35-nine-white-dotsJPG

Click on Terminal.

36-terminal-searchJPG
37-terminal-windowJPG

If you do a Google search for “common Linux terminal commands,” you should find some nice cheat sheets to use as a reference. Let’s try a few common commands below.

The following command retrieves a list of all the files and folders in the current directory.

ls
38-ls-commandJPG

If you want to change to the desktop, type:

cd Desktop

If you want to get the path to the current directory, type:

pwd

To go up one directory, type:

cd ~

To update the list of packages, type:

sudo apt-get update

The sudo keyword enables you to run a command as an administrator.

At this stage, it would be useful for you to install htop, an interactive system-monitor process-viewer and process-manager. To install it, type the following command:

sudo apt-get install htop

If at any point you want to remove it, you can type the following command:

sudo apt-get remove htop

To run, htop, you type:

htop

You can reboot the system using the following command:

sudo reboot

Finally, to shutdown the system, you type the following command:

sudo poweroff

How to Install Ubuntu 20.04 and VirtualBox on Your Computer

In this tutorial, we will install Ubuntu and Virtual Box on our personal computer. My machine is running Windows 10. Let’s walk through this whole process, step-by-step, so you understand how to do it no matter what operating system you have.

Ubuntu is a popular distribution (i.e. flavor) of the Linux operating system and is fully supported by ROS, the most popular framework for writing robotics software.

The process for installing Ubuntu has a lot of steps, so be patient and don’t give up if something isn’t working. Let’s get started!

You Will Need

Directions

Download the Ubuntu Image

Check Ubuntu Releases to find the latest version of Ubuntu that has long term support (LTS). As of the date of this writing, the latest version is Ubuntu 20.04 LTS (Focal Fossa), so click on that one. 

1-ubuntu-releasesJPG

Download the 64-bit PC (AMD64) desktop image (.iso file). It is a large file (about 2.5GB) and will take quite a while to download. Just go do something else and come back to it when it is finished.

Before you install the Ubuntu you just downloaded, you need to install Virtual Box. Virtual Box extends the capabilities of your host computer (i.e. your laptop or desktop PC) by enabling you to install and run an operating system in a new environment on top of your current operating system (Windows 10 in my case). The environment the new operating system will run in is known as a virtual machine (or guest).

Install VirtualBox

Go to the VirtualBox downloads page and select the version that is compatible with your computer. Install it. Once you’re done, your screen should look like this:

2-install-virtual-boxJPG

Detailed installation instructions for all operating systems (Windows, Mac OS, Linux, and Solaris) can be found in the instruction manual.

You can now delete the original executable file for VirtualBox (the one with the .exe extension). You don’t need it anymore.

Create a Virtual Machine

Now that VirtualBox is installed on your computer, we need to create a new virtual machine.

Open Virtual Box and click the New button in the toolbar.

10-start-virtual-boxJPG

Type in a descriptive name for your operating system. You can stick with the default machine folder. The machine folder is where your virtual machines will be stored. I prefer to install it on the D drive where I have more space.

3-name-and-operating-systemJPG

Also, select the operating system that you want to later install (Linux and Ubuntu_64 in the Type and Version fields).

Click Next to proceed.

The default memory size for me is 1024 MB. That is not sufficient for our purposes, so let’s raise it to 6470 MB, and then click Next to proceed.

4-raise-to-6470JPG

Make sure “Create a virtual hard disk now” is selected, and click Create.

5-create-virtual-machineJPG

Select “VirtualBox Disk Image (VDI)”, and click Next.

6-select-virtual-box-disk-imageJPG

Choose a Fixed size virtual hard disk so that you have better performance, and click Next.

7-fixed-sizeJPG

Go with something like 50 GB for the hard disk space. Then click Create.

8-go-with-50gbJPG

It will take several minutes to create the virtual hard disk, so be patient.

9-creating-hard-driveJPG

Install Ubuntu

Double-click on the left panel where you see the name of the virtual machine you just created.

10-double-click-left-panelJPG

A startup window will appear.

Click the Folder icon next to Empty. A popup box will appear that is titled “Optical Disk Selector.”

Click Add.

11-optical-disk-selectorJPG

Find the Ubuntu image you downloaded earlier in this tutorial. It is a .iso file. Select it.

Click Choose.

Click Start to proceed with that Ubuntu image.

Ubuntu should start launching.

12-ubuntu-launchingJPG

Click on “Install Ubuntu” to install Ubuntu. You should see a window that looks something like this.

13-install-ubuntuJPG

Click “Continue” to save the keyboard layout. The default English one is fine.

Select “Normal installation” and “Download updates while installing Ubuntu.” Then click Continue.

14-updates-and-other-softwareJPG

Select “Erase disk and install Ubuntu”. Then click “Install Now”.

15-install-nowJPG

Click Continue when it asks “Write the changes to the disks?”.

You will get to a point where you will need to set your time zone. It will be a big map of the world that should automatically detect your location. Click Continue.

Type in a computer name and pick a username and password. I select the “Log in automatically” option.

When installation is complete, click “Restart Now.”

16-restart-nowJPG

A message will say “Please remove the installation medium, then press ENTER:”. Just ignore it.

Go to File -> Close in the upper left part of the window.

Select “Power off the machine.” Click OK.

In the “Oracle VM Virtual Box Manager” window, highlight your virtual machine and click the green arrow up top that says “Start”.

You should now see your Ubuntu Linux desktop.

18-homepageJPG

Click the small white arrow in the upper-right portion of the screen. “Power Off” the machine.

19-power-off-machineJPG

Alternatively, you can open up a terminal window and type the following command:

sudo shutdown -h now

Highlight your virtual machine and go to Settings → Display and change your Video Memory to 128 MB. This will give you ample video memory. Click OK.

20-ample-video-memoryJPG

Also go to Settings → System → Processor, and adjust the number of CPUs to 4. Then Click OK.

21-4-cpusJPG

To make your screen larger, log back into Linux and go to your Settings. Then go to Display, and select your desired resolution.

resolution

If you have issues where your screen flips to portrait mode and gets stuck there, press CTRL + Alt + F1 to return to the login screen to fix the resolution.

You can follow this tutorial to enable clipboard sharing.

Congrats! You’re done!