Skip to content
 
 

Latest commit

 

History

27 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

ROS-Docker

Description

Working with robotics involves using many different software suites that can often clash with each other. In Python projects, environments like Anaconda or virtual enviroments are commonly used to manage dependencies. However, ROS installations can be tedious and are often prone to breaking. Therefore, using Docker containers is often a better option than relying on a base installation, as they provide a more stable and isolated environment.

1. Instructions to have a stable Ubuntu installation

Warning

  • Skip following instructions in this section if you plan to use any other OS except Ubuntu 22.04 or Ubuntu 20.04. Note that running a docker container is independent of this.
  • This section is for Computer with a Nvidia GPU ONLY. People with other GPUs should skip this section.

For any of your projects, having a stable Ubuntu Installation is of foremeost importance as the main image installed in you computer provides a stable foundation for everything else, be it a conda environment or as it is in this case, a Docker Image.

For this course, and for a stable installation, we recommend that you install either Ubuntu 20.04 or Ubuntu 22.04.

Note

Although as of the moment this tutorial is being written, Ubuntu has been out for around 4 months, it doesn't support Lambda stack yet, which we use to have a super stable installation that makes sure that you don't have to deal with driver issues.

Important

Remember to be equipped with the following things before you get started with the installation:

  1. A computer with an Ubuntu 22.04 or 20.04 installation (prefereable fresh but not important).
  2. A stable and high - speed internet connection
  3. High patience. At times, the downloads may be slow regardless of how fast your connection is. It may be just an hour or as long as 6 to 8.
  4. Habit of periodically checking in.

After you are done installing Ubuntu, follow the following instructions from Lambda Labs to install the Lambda stack

  1. Run the first command:

    wget -nv -O- https://lambdalabs.com/install-lambda-stack.sh | sh -

  2. Once it is done, proceed to reboot by doing:

    sudo reboot

  3. Now, proceed to update everything to the latest installation

    sudo apt-get update && sudo apt-get dist-upgrade

Note

  • It is a good practice to regularly update your system using: sudo apt-get update && sudo apt-get upgrade
  • followed by: sudo apt-get dist-upgrade
  1. We now utilize a GPU accelerated docker using the following command:

    sudo apt-get install docker.io nvidia-container-toolkit

And that's it, you have a very stable installation that includes PyTorch®, TensorFlow, CUDA, cuDNN, and NVIDIA Drivers!

2. Docker Setup (Ubuntu Only)

Now that you have all the prerequisites installed with Ubuntu, we can get started with Docker. Note that we are installing only Docker Engine, and not Docker Desktop.

(Official Instructions to install Docker Engine)

Note

  • Since we support only Ubuntu installations for this course, the following steps are for Ubuntu ONLY.
  • Follow the steps from official documentation, if you wish to use Docker Desktop for Windows or MacOS.

2.1 Installing Docker Engine

Caution

Skip this sub-section and move directly to sub-section 2.2 if you followed section 1

  1. Uninstall old packages:

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

  2. Install Docker Engine using Docker's apt repository, by running the sequence of commands below. They are in bullets to avoid confusion.

    • sudo apt-get update

    • sudo apt-get install ca-certificates curl

    • sudo install -m 0755 -d /etc/apt/keyrings

    • sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc

    • sudo chmod a+r /etc/apt/keyrings/docker.asc

    • echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] 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

  3. Install the Docker Packages:

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

  4. Verify that the Docker Engine installation is successful by running the hello-world image:

    sudo docker run hello-world

2.2 Post Installation steps

After installation, for Ubuntu based installation, you must run the following commands:

  1. sudo groupadd docker
  2. sudo usermod -aG docker $USER

Now, reboot your system with:

  1. sudo reboot

Login again and run the following command:

  1. newgrp docker

Finally, to verify that we can run docker without sudo, run the hello-world container using the command:

  1. docker run hello-world

If it runs, you have successfully run the post-installation steps.

3. Setting up the ROS environment

We are finally ready to use our ROS Docker image. To do that, clone this repo, build the docker image, and run it using the following steps:

3.1. Install git:

sudo apt-get install git

3.2. Building the Docker Image:

  1. Clone this repository using the command:

    git clone https://github.com/Kelebrimbor97/ROS-Docker.git

Tip

Remeber to do a git pull from within your repo to update your repo to the latest versions.

  1. Navigate to to location where the Dockerfile is stored:

    cd ROS-Docker/Scripts/Galactic/

  2. Build the docker Image using this command:

    docker build -t modelling_ros .

Important

Take a look at the comments on lines 9 and 10 of the in Scripts/Galactic/Dockerfile before you run this command.

Tip

  • modelling_ros can be replaced with any other name of your choice, but remember to replace it in future Dockerfiles you create.

3.3. Running a Docker container using the built Image

Note

  • The following 2 commands are what you have to use everytime you want to run the docker.
  1. Allow docker to have port access:

    xhost +local:docker

  2. Spin up a container by using the image created in the previous step:

    docker run -it --rm --name=project_0 --gpus=all --net=host --pid=host --privileged --env="DISPLAY=$DISPLAY" modelling_ros

Tip

  • You can again have a container name of you choice instead of project_0.
  1. It's Alive! If you see something like this, your docker container is up and running:

    root@User:/#

    If not, feel free to cry...

3.4. Execing into the Docker (Opening a separate terminal in same container)

Warning

  • Any changes you make to the docker container will not be saved and will be lost once the current container is shut down.

Once you have a container running, start using it as you would with a terminal. The only difference is that you never need to use sudo again.

For opening a different terminal in the same container, get the container name and exec into it. Example:

docker exec -it project_0 bash

4. Installing turtlebot3

Given that we have a base image with ROS installed, we will create another image from the base one for our turtlebot3. Think of this similar to having a child class inheriting qualities from the parent class.

For doing that, navigate to Scripts/Galactic/Projects/Turtlebot3 and simply build the image from the Dockerfile using the following command:

docker build -t turtlebot3_galactic .

5. Using Visual Studio Code

If you would like to use VS Code as a development enviornment, there is an excelent integration with Docker that is recommended. Follow these steps to set up a workspace for VS Code and Docker.

5.1. Install VS Code and devcontainer extension

  1. Run the following command in a terminal to install vs code

sudo snap install --classic code # or code-insiders

  1. Open vs code and press ctrl+shift+x

  2. type "Dev Containers" and download the extension

5.1. Create a workspace folder and copy boilerplate files

Create a workspace folder where you would like your project and copy the .devcontainer folder from Scripts/Galactic/VSCode into it.

ex.

  1. cd ~

  2. mkdir myworkspace

  3. cp ./ROS-DOCKER/Scripts/Galactic/VSCode/.devcontainer ./myworkspace

5.2. Open the folder in a Docker container

  1. Open the workspace folder in vs code.

  2. Press ctrl+shift+P and type "Dev Containers: Open Folder in Container" and press enter

  3. The VS Code window should reload and you are now working in a docker container!

Tip

  • You can open more terminals with ctrl+shift+`

About

This repo contains the instructions for setting up a Docker environment for ROS completely from scratch including CUDA enabled option for the base OS

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages