Docker is a platform that allows you to package and run applications and their dependencies in a consistent and isolated environment. It uses containers, which are lightweight, standalone, and executable software packages that include everything needed to run a piece of software, including the code, runtime, libraries, and system tools. Docker makes it easy to develop, deploy, and run applications consistently across different environments, ensuring that they work the same way regardless of where they are run.
Imagine Docker as a way to package and share your projects with others easily, regardless of the technical environment they are using. It helps avoid the "it works on my machine" problem, where a project runs on one computer but not on another due to differences in software versions, configurations, etc.
Let's simplify it with an analogy:
Imagine Docker as a Lunchbox for Your App:
Imagine you've developed a cool robot software (a ROS2 package) that loves the latest and greatest features of Ubuntu 22. But, oh no! The robot you want to run it on is still stuck in the past, using ROS1 on Ubuntu 18.
<aside> 🔖 NVidia jetson do not keep up with current ubuntu version hence they are stuck in older version images which is why we use docker to run ROS2 packages.
</aside>
Now, this is where Docker comes to the rescue. Docker is like a magic box that you can put your software in, along with all its friends (dependencies), and it doesn't care where it's going to run. It just works the same way everywhere.
So, here's what you do:
Create a Box for Your Software (Dockerfile): You write down a set of instructions in a file (let's call it a Dockerfile) that tells Docker how to build a special box (container) just for your robot software. You say, "Dear Docker, please make a box that has Ubuntu 22 and all the things my software likes."
# Dockerfile
FROM ubuntu:22.04
# Install ROS2 and whatever your software needs
RUN apt-get update && apt-get install -y ros-foxy-your-package
Build the Box (Docker Build): You ask Docker to read your instructions and build this special box for you.
docker build -t my-ros2-box .
Take Your Box Anywhere (Docker Run): Now, whenever you want to run your software, you just tell Docker to use the box you made, regardless of what's on the robot.
docker run -it --rm my-ros2-box
Docker makes sure everything your software needs is inside the box, and it runs just as happily on Ubuntu 18 with ROS1 as it does on Ubuntu 22 with ROS2.
So, you've basically created a portable environment for your software using Docker, allowing it to run smoothly on different robots, no matter what versions of operating systems or ROS they have. It's like your software is in a bubble, and Docker helps it carry its own world wherever it goes. Cool, huh?
To install Docker on Ubuntu, you can use the following commands: