Containers are built from Docker images and these images can be pulled from Docker Hub (https://hub.docker.com/). We can pull ROS containers from the ros repository using the following command:
$ sudo docker pull ros:melodic-ros-core
If everything is successful, you see the output shown here:
Successful Docker pull
You can choose the specific version of ROS you want to work with. The best suggestion for any application is to start with melodic-core, where you would continue to work and update the container related to your project goal and not have other unnecessary components installed. You can view Docker images using this command:
$ sudo docker images
By default, all of the containers are saved in /var/lib/docker. Using the preceding command, you can identify the repository name and tag. In my case, for the ros repository name, my tag was melodic-ros-core; hence, you could run the ros container using the following command:
$ sudo docker run -it ros:melodic-ros-core
Other information the $ docker images command gives is the container ID, which is 7c5d1e1e5096 in my case. You will need it when you want to remove the container. Once you're inside Docker, you can check the ROS packages that are available using the following command:
$ rospack list
When you run and exit Docker, you would've created another container, so for beginners, it's quite common to create a list of containers unknowingly. You could use $ docker ps -a or $ docker ps -l to view all active/inactive containers or the latest container and remove containers using $ docker rm <docker_name>. To continue working in the same container, you could use the following command:
$ sudo docker start -a -i silly_volhard
Here, silly_volhard is the default name created by Docker.
Now that you've opened the same container, let's install an ROS package and commit changes to the Docker. Let's install the actionlib_tutorials package using the following command:
$ apt-get update
$ apt-get install ros-melodic-actionlib-tutorials
Now, when you check the ROS packages list once again, you should be able to view a few extra packages. Since you have modified the container, you would need to commit it to experience the modifications while reopening the Docker image. Exit the container and commit using the following command:
$ sudo docker commit 7c5d1e1e5096 ros:melodic-ros-core
Now that we have installed ROS on Ubuntu and VirtualBox, let's learn how to set up the ROS workspace.