0
$\begingroup$

Rosanswers logo

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


Originally posted by chrisb on ROS Answers with karma: 67 on 2016-12-14

Post score: 4


Original comments

Comment by spmaniato on 2016-12-14:
The "Deployment example" section here might help: https://hub.docker.com/_/ros

Comment by chrisb on 2016-12-16:
Thank you, this example only shows connections in the docker network though.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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/userguide/networking/default_network/binding/


Originally posted by Michael Johnson with karma: 154 on 2016-12-14

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by gvdhoorn on 2016-12-15:
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).

Comment by chrisb on 2016-12-16:
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.

Comment by gvdhoorn on 2016-12-17:\

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.

Comment by gvdhoorn on 2016-12-17:
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.

Comment by GeorgeMD on 2018-07-25:
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?

Comment by Michael Johnson on 2018-07-25:
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.

Comment by GeorgeMD on 2018-07-25:
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.

Comment by Alexandr Buyval on 2019-02-08:
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?

Comment by MH_Ahmed on 2019-12-22:
I'm facing a similar issue with docker-compose, when I have 2 services with host network, one container(recent built) runs and the other doesn't run at all.

Did anyone manage to solve this issue?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.