Docker images are akin to packages such as virtual machines or complete systems that are already set up. There are servers that provide the images, and users only have to download them. The main server is Docker Hub, which is located at https://hub.docker.com. Here, it is possible to search for Docker images for different systems and configurations.
Well! All ROS Docker images are listed in the official ROS repository on the web at https://hub.docker.com/_/ros/. We will use ROS Kinetic images, which are already available here:
$ sudo docker pull ros
$ sudo docker pull kinetic-ros-core
$ sudo docker pull kinetic-ros-base
$ sudo docker pull kinetic-robot
$ sudo docker pull kinetic-perception
Similarly, we could pull ROS Melodic images, which are also already available there:
$ sudo docker pull ros
$ sudo docker pull melodic-ros-core
$ sudo docker pull melodic-ros-base
$ sudo docker pull melodic-robot
$ sudo docker pull melodic-perception
After the container is downloaded, we can run it interactively with the following command:
$ docker run -it ros
This will be like entering a session inside the Docker container. The preceding command will create a new container from the main image wherein we have a full Ubuntu system with ROS Kinetic already installed. We will be able to work as in a regular system, install additional packages, and run the ROS nodes.
We can list all the Docker containers available and the origin of their images:
$ sudo docker ps
Congratulations! We have completed the Docker installation. To set up the ROS environment inside the container in order to start using ROS, we have to run the following command (ros_version: kinetic/melodic):
$ source /opt/ros/<ros_version>/setup.bash
However, in principle, running docker should be enough, but we could even SSH into a running Docker container as a regular machine, using name or ID.
$ sudo docker attach 665b4a1e17b6 #by ID ...OR
$ sudo docker attach loving_heisenberg #by Name
If we use attach, we can use only one instance of the shell. So, if we want to open a new terminal with a new instance of a container's shell, we just need to run the following:
$ sudo docker exec -i -t 665b4a1e17b6 /bin/bash #by ID ...OR
$ sudo docker exec -i -t loving_heisenberg /bin/bash #by Name
Moreover, Docker containers can be stopped from other terminals using docker stop, and they can also be removed with docker rm.