Docker container with pre-installed Ubuntu20.04 and ROS Noetic: A Comprehensive Guide for Beginners

Sepideh Shamsizadeh
9 min readOct 10, 2023

--

Docker.

Welcome to the exciting world of Docker, where containerization opens up new possibilities in software development and deployment. In this journey, we will unravel the mysteries of Docker, guiding you step-by-step through the fundamentals. But that’s not all — brace yourself for a hands-on experience as we delve into installing Docker alongside ROS Noetic on Ubuntu 20.04.

By the end of this guide, you’ll not only grasp the core concepts of Docker but also seamlessly integrate it with the Robot Operating System (ROS) Noetic, bringing together the power of containerization and robotics development. Let’s embark on this adventure, unlocking the potential of Docker in your software development endeavors.

What is Docker?

Docker is a platform designed to make it easier to develop, deploy, and run applications using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package. This ensures that the application runs reliably across various computing environments.

Key Docker Concepts:

1. Containerization:

Utilizes container technology to encapsulate applications and dependencies, ensuring consistency across environments.

2. Images and Containers:

Images are lightweight, standalone packages containing everything needed to run the software, while containers are runtime instances of these images, ensuring isolation.

3. Dockerfile:

Dockerfiles are the blueprints for images, providing instructions for building an image, specifying dependencies, and configuring the environment.

4. Portability:

Docker containers run seamlessly on any machine with Docker installed, offering a consistent environment for development and deployment.

5. Docker Hub:

A cloud-based registry service, Docker Hub centralizes Docker images, simplifying the sharing and distribution of containerized applications.

Benefits of Using Docker:

  1. Consistency Across Environments: Ensures uniformity from development to testing and production.
  2. Portability: Runs on any machine, simplifying deployment across diverse environments.
  3. Isolation: Provides process isolation, preventing conflicts between dependencies.
  4. Resource Efficiency: Lightweight containers use fewer resources and scale quickly.
  5. Rapid Deployment: Facilitates fast and consistent deployment with pre-built images.
  6. Scalability: Easily scales applications horizontally for optimal resource utilization.
  7. Version Control: Enables version-controlled management of dependencies and configurations.
  8. Dependency Management: Simplifies handling of dependencies within encapsulated containers.
  9. DevOps Integration: Key tool in DevOps practices, streamlining CI/CD workflows.
  10. Microservices Support: Supports microservices architecture for independent development and scaling.
  11. Vibrant Ecosystem: The thriving community and Docker Hub offer a rich repository of pre-built images.

If your computer has a different version of Ubuntu or you’re using Windows and don’t want to switch to Ubuntu 20 for working with ROS Noetic, this tutorial is here to help. It’s all about getting your development environment ready without the need to change your operating system. So, let’s kick things off by installing Docker.

Installing Docker on Ubuntu:

OS requirements

To install Docker Engine, you need the 64-bit version of one of these Ubuntu versions:

  • Ubuntu Lunar 23.04
  • Ubuntu Kinetic 22.10
  • Ubuntu Jammy 22.04 (LTS)
  • Ubuntu Focal 20.04 (LTS)

For more details check the Docker website.

Update Ubuntu:

Open a terminal and run:

sudo apt update && sudo apt upgrade

Install Docker Dependencies:

sudo apt install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release

Add Docker GPG Key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Set Up Docker Repository:bashCopy code

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

Install Docker:

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

Run Docker without sudo (Optional):

sudo usermod -aG docker $USER

Log out and log back in or run su - $USER to apply the group changes.

Verify Installation:

docker --version

Also, test with:

docker run hello-world

Installing Docker on Windows:

  1. Download Docker Desktop: Visit Docker Desktop for Windows and download the installer.
  2. Install Docker Desktop: Follow the installation instructions in the Docker Desktop installer.
  3. Run Docker Desktop: Once installed, the Docker Desktop should start automatically. Look for the Docker icon in the system tray.
  4. Verify Installation: Open PowerShell and run:
docker --version
  1. Also, check Docker Compose:
docker-compose --version

Now you’re all set! Docker is installed on both Ubuntu 20 and Windows, ready for your ROS Noetic adventures.

Building a Docker Container for ROS Development

In the realm of Robotics and ROS (Robot Operating System) development, creating a Docker container provides a streamlined and reproducible environment. Let’s embark on a journey to build a Docker container tailored for Ubuntu 20.04 with ROS Noetic and essential modules.

Build the Dockerfile:

# Create a new folder for Docker
cd ~
mkdir ~/Docker

# Move into the Docker folder and create a Dockerfile
cd ~/Docker
touch Dockerfile

This sets up the directory structure and creates an empty Dockerfile for your container.

Fill Dockerfile with Installation Instructions:

echo 'FROM osrf/ros:noetic-desktop-full' > Dockerfile && echo 'ARG USER=user' >> Dockerfile && echo 'ARG DEBIAN_FRONTEND=noninteractive' >> Dockerfile && echo 'RUN apt-get update && apt-get install -y ros-noetic-moveit ros-noetic-ros-controllers ros-noetic-gazebo-ros-control ros-noetic-rosserial ros-noetic-rosserial-arduino ros-noetic-roboticsgroup-upatras-gazebo-plugins ros-noetic-actionlib-tools terminator python3-pip && rm -rf /var/lib/apt/lists/*' >> Dockerfile && echo 'RUN pip install flask flask-ask-sdk ask-sdk' >> Dockerfile && echo 'WORKDIR /home/${USER}' >> Dockerfile

This Dockerfile starts from the official ROS Noetic desktop-full image and adds additional packages and dependencies necessary for your robotics development. It also installs the Terminator terminal emulator and Flask for web development.

Build the Docker Container:

# Build the container and name it ros-noetic-container
docker build ~/Docker -t ros-noetic-container

This command uses the Dockerfile to build a container image named “ROS-Noetic-container.”

Create Shared Volumes:

# Create a folder called Workspace for sharing between PC and Docker container
mkdir ~/Volumes

This creates a directory on your host machine that will be shared with the Docker container. Sharing a folder between your PC and the Docker container is essential for seamless collaboration and data persistence. This shared volume acts as a bridge, enabling the exchange of files and data between your local machine and the container. It ensures that any changes made within the container, such as code modifications or project updates, are reflected on your PC, providing a synchronized development environment. This shared folder approach eliminates the risk of losing crucial work and fosters a fluid development process, allowing you to harness the benefits of Docker containerization while maintaining the flexibility and accessibility of your local file system.

Run the Docker Container:

# Run the ros-noetic-container and share Volumes folder and network configuration
docker run -it --rm --user=$(id -u $USER):$(id -g $USER) --env="DISPLAY" --volume="/etc/group:/etc/group:ro" --volume="/etc/passwd:/etc/passwd:ro" --volume="/etc/shadow:/etc/shadow:ro" --volume="/etc/sudoers.d:/etc/sudoers.d:ro" --net host -v /home:/home -v ~/Volumes:/home/usr/ ros-noetic-container

This command starts the Docker container in interactive mode, sharing your host user and group IDs to avoid permission issues. It also shares the necessary volumes and network configuration.

Start Terminator Application:

# Start the terminator application for better terminal window management
terminator -u

Terminator is a terminal emulator that provides a more advanced terminal window management experience.

Verify Container Environment:

# Verify that you're in a Docker container running Ubuntu 20.04
lsb_release -a

This command confirms that you are indeed inside a Docker container with Ubuntu 20.04.

Verify ROS Installation:

# Verify that ROS is correctly installed in the container
roscore

Running roscore checks if the Robot Operating System is functioning properly within the Docker container.

Exiting Docker:

To exit the Docker container, you can use the `exit` command or press `Ctrl + D`. This will terminate the interactive session inside the container, and you’ll be back in your host machine’s terminal.

Starting Docker Container:

Whenever want to work with this built container you should run the below command in a terminal.

docker run -it --rm --user=$(id -u $USER):$(id -g $USER) --env="DISPLAY" --volume="/etc/group:/etc/group:ro" --volume="/etc/passwd:/etc/passwd:ro" --volume="/etc/shadow:/etc/shadow:ro" --volume="/etc/sudoers.d:/etc/sudoers.d:ro" --net host -v /home:/home -v ~/Volumes:/home/usr/ ros-noetic-container

Once your Docker container is up and running, seamlessly connect Visual Studio Code to it. Download Visual Studio Code here and install it. After installation, head to the “Extensions” tab and add the following extensions for C++ and Python, the go-to languages in ROS development:

- ms-vscode.cpptools
- twxs.cmake
- ms-vscode.cmake-tools
- ms-python.python
- redhat.vscode-xml
- ms-vscode-remote.remote-containers

Now, navigate to the “Remote Explorer” tab in Visual Studio Code:

Right-click on the running ros-noetic-container.

Select “Attach to Container.”

Voila! You now have Visual Studio Code seamlessly integrated with your ros-noetic-container, ready for development in Ubuntu 20.04 and ROS Noetic.

Save Docker Container:

If you’ve made modifications to the container, like installing new packages, tools, or libraries that you want to preserve for future use, follow these commands to capture those changes effectively.

List Running Containers:

docker ps

This command shows the list of running containers, and you need to note the CONTAINER ID or NAME of the container you want to commit.

Commit Changes:

docker commit CONTAINER_ID_OR_NAME new_image_name

Replace CONTAINER_ID_OR_NAME with the actual ID or name of your container and new_image_name with the desired name for the new image.

Example:

docker commit my_container ROS-Noetic-Updated

This command creates a new image named ROS-Noetic-Updated with the changes made in the specified container.

Now, you can start a new container based on this updated image whenever you want to resume your work with the saved changes.

Remember, it’s good practice to use version control systems (e.g., Git) for managing your code changes, and Docker images can capture the environment and dependencies, providing reproducibility.

Docker Hub: Home of Container Magic

Docker Hub is where container wonders happen. It’s the ultimate space for Docker images, making sharing and finding containers a breeze. Need an image? Docker Hub has it. It’s like a digital library for containers, making your software adventures smoother and more fun!

Embarking on this Docker adventure has been quite a journey, unlocking the vast potential of containerization in software development. We’ve demystified Docker, explored its key concepts, and seamlessly integrated it with the Robot Operating System (ROS) Noetic on Ubuntu 20.04. From the consistency of environments to the agility of deployment, Docker has proven to be a game-changer.

As we bid farewell to this guide, remember that Docker is not just a tool; it’s a gateway to a vibrant ecosystem. Whether you’re ensuring consistency across environments, isolating processes, or scaling applications horizontally, Docker is your ally. The journey doesn’t end here; it extends to the realms of microservices, DevOps integration, and a rich repository of pre-built images on Docker Hub.

For those on different versions of Ubuntu or Windows, fear not — this guide stands as a testament that you can harness the power of Docker without changing your operating system. As you navigate the world of containers, don’t forget to explore Docker Hub, the home of container magic. It’s your digital library for containers, making software adventures smoother and more enjoyable.

So, here’s to Docker, to ROS Noetic, and to the endless possibilities of containerized development. Happy coding! 🚀

References

--

--