Session 0: ROS2 in Docker¶
Installing Docker¶
In this lab we are going to use Docker to deploy a system environment on the student’s host machines, which can be accessed via your web browser. This allows us to stay agnostic to your specific operating system and hardware setup. To learn more about Docker and install it on your system, please refer to the official documentation.
Creating persistent storage¶
While changes such as additional installations inside your container will be persistent unless you remove it, it’s better to be safe than sorry and create additional persistant storage for your course work. To do so we will create a Docker volume, which we will hook up to your container. In case anything breaks and you have to start a new container, at least your actual work will be preserved.
In a terminal, type:
sudo docker volume create arams_volume
If you’re using Windows, use PowerShell and omit sudo
:
docker volume create arams_volume
Launching the container¶
If you’re using a Linux machine, open a terminal and type:
sudo docker run -v arams_volume:/home/ubuntu/docker_volume -p 6080:80 --name ros2foxy tiryoh/ros2-desktop-vnc:foxy
On Windows, use PowerShell and omit sudo
.
Docker will continue to pull information about the image and launch a contianer from it. Windows users can start and stop the container from inside the Docker Desktop tool.
On Linux, use the terminal commands:
sudo docker container stop ros2foxy
sudo docker container start ros2foxy
Accessing your ROS2 container¶
Using a web browser of your choice navigate to 0.0.0.0:6080
. You will find yourself in a Ubuntu 20.04 desktop environment. A terminal can be found in the System Tools tab of the start menu. Currently only vim is installed as an editor. If you want to install another editor, type
sudo apt update
sudo apt install <editor of your choice, e.g. gedit>
In your home directory (/home/ubuntu/
or ~
) you will find the directory docker_volume
in which the volume you created is mounted. Use it as a base directory for your course work.
The container broke¶
No worries. Retrace your steps from here. Windows users can delete the old container from within the GUI tool, Linux users use
sudo docker container rm <name>
name
refers to ros2foxy
. Be aware, that you will not be able to start a new container with the same commands using the same name unless you remove the old one. Also port 6080 will not be available while your old container is still running. You will need to stop it first.