ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
4

How to use Docker on a host together with non Docker machines (ROS)

asked 2016-12-14 11:39:19 -0600

chrisb gravatar image

Hello,

I was searching for this during the last days but couldn't find a suitable answer.

I would like to run ROS in a disposable development environment on my machine together with other machines that I don't want to specially modify for my docker setup (Other people will use them without using docker on there machines).

It is basically a question on how to setup the network config in the right way. I need to run docker on my PC, configured so that all external machines see ROS inside my container as if it would run directly on my host. This should be independent on where the roscore is running. The problem is that the docker container does not see the IP of my host. And since the IP range of the container is not the same as the one of my host network I would need to somehow specify the ROS_MASTER/IP different from how I would do it on the host machine. I saw examples where multiple ROS containers are connected, but those are usually all behind the docker bridge and therefor have the same IP range.

So the question is, how can I make ROS in a container on my host machine accessible to external machines, while the external machines use the IP of my HOST for the connection?

Thanks in advance.

Chris

edit retag flag offensive close merge delete

Comments

The "Deployment example" section here might help: https://hub.docker.com/_/ros

spmaniato gravatar image spmaniato  ( 2016-12-14 14:27:32 -0600 )edit

Thank you, this example only shows connections in the docker network though.

chrisb gravatar image chrisb  ( 2016-12-16 18:43:18 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2016-12-14 16:28:18 -0600

Michael Johnson gravatar image

updated 2016-12-16 17:40:15 -0600

You should be able to run docker with the host network --net=host.

roscore
rostopic echo /test
docker run -it --rm --net=host ros:indigo-ros-base rostopic pub /test std_msgs/String "hello"

As pointed out below, this will remove the network level isolation that docker provides. If you need to preserve isolation then it becomes more complicated as you need to explicitly expose the ports ROS uses in the docker command and it uses a very wide range of ports (normally 32768 to 61000).

This page should point you in the right direction if you need it https://docs.docker.com/engine/usergu...

edit flag offensive delete link more

Comments

2

Note that using the --net=host option will cause your containers to not be isolated anymore wrt the network stack (ie: they have full access to it).

gvdhoorn gravatar image gvdhoorn  ( 2016-12-15 07:14:55 -0600 )edit

Perfect, that works. Regarding the isolation issue, that's true but OK for my development environment. The only other option is to expose each necessary port for my applications and the roscore which complicates a spontaneous spin-up of new applications quite a bit I guess.

chrisb gravatar image chrisb  ( 2016-12-16 18:46:03 -0600 )edit

The only other option is to expose each necessary port for my applications and the roscore [..]

Afaik, it should be possible to setup IP routing between a Docker net and your local (physical) network. The net effect would be the same, but container isolation is preserved.

gvdhoorn gravatar image gvdhoorn  ( 2016-12-17 09:16:15 -0600 )edit

Bit old perhaps (and not as 'easy' as --net=host), but: Four ways to connect a docker container to a local network. And docker/Advanced Network Configuration, of course.

gvdhoorn gravatar image gvdhoorn  ( 2016-12-17 09:20:41 -0600 )edit

Using --net=host, -e ROS_MASTER_IP=http://172.17.0.1:11311 and -e ROS_IP=172.17.0.1 I was able to echo on host a topic published in docker. But I need the other way around to work as well, where docker subscribes to a topic published by host and it doesn't work whatever I do. Any ideas?

GeorgeMD gravatar image GeorgeMD  ( 2018-07-25 05:04:01 -0600 )edit

When using --net=host the docker network is not used. This means both the host and the container share an IP address.

To fix this, you can just use -e ROS_MASTER_IP=http://localhost:11311 -e ROS_IP=127.0.0.1 and it should work. You can also just ignore them as these are the default values.

Michael Johnson gravatar image Michael Johnson  ( 2018-07-25 08:44:22 -0600 )edit

Thanks, I got it working before I saw this. Now I am at a point where it only works if I run the subscriber in docker before I run the publisher on host. It's the same with the variables you recommended.

GeorgeMD gravatar image GeorgeMD  ( 2018-07-25 09:24:39 -0600 )edit

I faced with the same issue. If I run the publisher before the subsciber in docker the communication does not work. GeorgeMD have you solved it?

Alexandr Buyval gravatar image Alexandr Buyval  ( 2019-02-08 08:22:30 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2016-12-14 11:39:19 -0600

Seen: 7,594 times

Last updated: Dec 16 '16