The Ros container in Docker is connected to the ROS host

Source: Internet
Author: User
The Ros container in Docker is connected to the remote ROS host

Docker is currently a popular open-source application container engine, and ROS (robot operating system) is a popular robotic operating system. In combination, it is a possibility to study the cloud robot. 1. Preparation

(1) Two computers AB, preferably in the same network segment;
(2) PC A-installs Docker and downloads Ros Mirror, computer B downloads and installs Ros (non-mirrored) with the same distribution as in A; 2. Configure 3 environments

(1) Get the IP address of host A and B, the IP of my host A is, the IP of Host B is;

(2) Run the ROS image in host A, get the Ros container (understanding of the container-container, borrow the explanation of the official website-"A running instance of image"), run ifconfig in the container to get the relative IP address of the container in host a. Mine is "";

F8289B197A45 represents the container ID, in fact, this ID  is very long, here also just intercepted the first few easy to operate

(3) in Host A. BASHRC (hidden file in home directory, crtl+h manifest) file, add:

Export ros_hostname=
Export ros_master_uri=

Of these, the 11311 port is the communication port of the Turtlesim test below.
(4) in the. bashrc file in Host B, add:

Export ros_hostname=
Export ros_master_uri=

(5) Add a variable in the Ros container of host a (see IP above)
Add the environment variable in the directory/etc/profile, the Editor VI available in the container, and the Vim nano gedit need to be downloaded again in the container. With regard to the use of VI, it is important to remember that the command mode, insertion mode (insert mode), the bottom line mode (Command mode) in the three modes of operation of the different, confused, will feel the input is very strange.
The input content in profile is:

Export ros_hostname=
Export ros_master_uri=

Save exit.
Run the command to make it effective:

$ source/etc/profile
$ source/opt/ros/indigo/setup.bash
3. Testing

(1) Run the following command in Host B (equipped with the ROS system):
To activate the Ros service:

$ roscore

Open a new window, run Turtlesim:

$ rosrun Turtlesim Turtlesim_ndoe

(2) test Rostopic in Host A, rosnode whether it shows:
Enter the command separately:

$ rostopic List
$ Rosnode List

Can be displayed, indicating that host a can communicate with Ros Host B and then test the connection in the container.

(3) In the Ros container of Docker in host A, test rostopic, Rosnode whether the display:
Similar to the above command

Can be shown to indicate that the ROS container can communicate with the remote ROS host. 4. Testing for data transmission

Preliminary assumption: The transmission of rosbag data, in the Ros container by running the Rosrun turtlesim turtle_teleop_key command, control the keyboard, the remote Ros system can be controlled by the movement of Turtlesim.

Try 1:a host-"B host, in host A, regardless of the container, you can control the remote ROS Host B in the Turtlesim of the small turtle movement."

Try to 2:a the host in the container ros-"a", (you can understand that the container in a and host a system isolation, similar to the virtual machine), in a in the container to run control commands, you can control the host of a in the turtlesim of the small turtle movement.

Try 3:a the container in the host ros-(host a)-"B host"
Similar to the above control, you want to run the control command in the container Ros in host A, and control the movement of the Turtleism small turtle running in Host B.
In this case, although running the Rostopic list Rosnode in the container Ros can capture the associated topic and list of the Turtlesim run by Host B, it is impossible to control the movement of the small turtle. When the value of the output speed is also unresponsive,

$ rostopic Echo/turtle1/cmd_vel

The speed in the window is not displayed. Do not know the reason for the moment, still in the inquiry, if there are new discoveries, will be written in the following blog.

The movement of the small turtle in the control Turtlesim should be as follows:

5. Note the situation

(1) Open multiple windows of the same container:
Typically, when we do command-line operations, we open multiple windows, as is the case with Docker containers.
Open the other terminal box of the Docker container, there are two kinds of commands:

Docker attach <container ' s id>
Docker Exec-ti <container ' s id>/bin/bash

Here, the second type of Docker exec applies to our operations
For the difference between the people, I Google to the explanation,

The following table is probably summarized from StackOverflow.

Command Description
Docker Attach container ID Attaching to the running process
Docker Exec-ti Container Id/bin/bash Running new things, it would be a shell

The former is attached to the process and the latter opens a new interactive shell.

(2) After opening the new shell, enter Rostopic, rosnode error cannot find this command
In the container, enter the following command:

Refer to: Let's install Turtlesim packages

(3) encountered Turtlesim This package did not find the problem.
This is because the package that comes with the different ROS images is not necessarily complete, some of which contain only the core, and what is missing is what you install.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.