How to Install Docker on Ubuntu

docker_logo

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 docker-compose

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 tool 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!