The Future of Cancer Prevention and Therapy

Cancer is one of the most pervasive diseases to affect the new millennium. With all of the research that has been conducted, what does the future of prevention look like? According to the American…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




A simple quickstart with Docker and ROS in Ubuntu

Docker with ROS? No problem, just follow these easy steps!

Docker represents a valid and easy solution to configure, deploy and run an application, creating an isolated environment called a container.

Docker automatically takes care of networking, in order to allow the communication between different containers, making life easy for the developer that must not necessarily dig into too many details to be able to run and the application.

Anyway, also ROS has its own network managing system, and some steps must be followed before being able to communicate data among topics published/subscribed by different containers. This article will present a quick tutorial to use ROS with Docker, letting containers executing nodes with the roscore running on the host. In particular, one first node will stream images from the webcam into a topic, that will be visualized from rviz installed in the host. This way, it will be necessary to build our own image and run a script at container initialization. Also, we will generalize the approach such that other nodes will publish a simple message, that will be reachable inside any other container. The host will be a machine running Ubuntu 18.04 LTS and the ROS version will be Melodic, but it can be easily adapted for other versions (as well as other OS if you are familiar with basic Docker syntax).

In this part of the guide, we will configure and build a Docker image in charge of streaming data from a webcam. My suggestion is to start with the official ROS image, adding our necessary packages and script. In particular, I will follow the aforementioned approach, thus adding two additional files, the Dockerfile with build instructions, and a script to run when a container is initialized.

Let’s start with the Dockerfile. A Dockerfile is useful to avoid having to run the set of commands each time we instantiate a container, also downloading any additional package only once at compile time. For our purposes, the very minimal Dockerfile will be the following:

The file is quite simple to understand, I will just introduce some command.

The first line is used to start with the official ROS image. If nothing else is specified, the ros:latest image will be downloaded by default (i.e., at time of writing, the ROS Melodic version).

The RUN command is used to download all the necessary packages; in particular, the ros-melodic-usb-cam will be installed.

The last three commands are used to copy our script in the container, give it the necessary privileges to be executed and call it when starting the container.

To build the image, the command is:

That’s all! You can already run your image!

In the host, just initialize ROS. If you already sourced your setup.bash, you only need to type:

In another terminal, you can run our image as follows:

Let’s have a detailed look at the parameters. From the official documentation:

Simply, this option will imply that you will be able to use your stdin, for example, your keyboard. You can run your container without this option, but then you will not be able to close it with a classic ctrl+c .

With --rm the container will be destroyed at the exit.

With the --device option, we are passing a host device to the container, in this case, your webcam. To learn more details, you can check the article of Jan Chęć, available here.

About the --net option, we are using the host network. Please refer to the note at the end of the article to learn more.

Finally, let’s assume that other containers need to publish other messages. In this case, you can simply run:

That’s all! The next steps will be to experiment and modify your image and script, trying more Docker options, and to configure your own bridge network as in the official guide. Also, consider upgrading to Docker Compose to launch different nodes in different containers when your application will grow, being composed by multiple node instances among many containers and when you will feel more comfortable with the basics of Docker!

In Docker there are three possibilities of networking:

Did you like this article? Let me know, I will be more than happy to continue writing guides for the next steps, organizing a more efficient setting and using Docker Compose to deploy our complete application!

Add a comment

Related posts:

Who is The Real Virus ? Humans Vs Corona

He is going from country to country ,unstoppable, killing thousands without any mercy , crushing economies and leaving millions either dead or hungry , you feel that this hidden enemy is full of rage…

A Complete Guide for GSoC

After facing so many questions and providing answers to so many open source enthusiasts about Google Summer of Code, shortly said GSoC, I decided to write a blog answering almost all the questions…

CALVOCAST EP019

Esta semana os traemos, en mierdas varias: nuestros problemas con los AirPods Pro y cómo los solucionó Apple; además, hablamos de por qué Lucas ha vuelto a comprar un Galaxy S21 Ultra; de lo que nos…