No rostopic response when run in docker container
When I run rostopic hz <topic-name>
inside a docker container to get the publishing rate of a topic via the containers logs I don't get any output. (If I echo the same topic I get what I expect.) Do I miss something here?
In [1]: import docker
In [2]: cli = docker.from_env(version='auto')
In [3]: roscore = cli.containers.run(image='osrf/ros:indigo-desktop-trusty', network='host', command='
...: roscore', detach=True)
In [4]: publisher = cli.containers.run(image='osrf/ros:indigo-desktop-trusty', network='host', command
...: ='rostopic pub /topic_to_observe std_msgs/UInt8 42 -r 1', detach=True)
In [5]: rostopic = cli.containers.run(image='osrf/ros:indigo-desktop-trusty', network='host', command
...: ='rostopic hz /topic_to_observe', detach=True)
In [6]: rostopic.logs()
Out[6]: ''
In [7]: subscriber = cli.containers.run(image='osrf/ros:indigo-desktop-trusty', network='host', comman
...: d='rostopic echo /topic_to_observe', detach=True)
In [8]: subscriber.logs()
Out[8]: 'data: 42\n---\ndata: 42\n---\ndata: 42\n---\ndata: 42\n---\ndata: 42\n---\n'
This looks like the output of an IPython console. Is this what you mean with "manually running"?
Right, I ran it in a IPython console which was no problem so far. If I run the command in my Ubuntu workstation environment I have the usual output:
... I expected to get something similar with
In [6]: rostopic.logs() Out[6]: ''
.I'm not sure I understand what you're asking, but that is probably just me.
Sorry, probably not clear enough: When I run
roscore
, a publisher node androstopic hz
I would expect the same output ofrostopic hz
when (a) I run them on Ubuntu directly or (b) I run them inside Docker containers (like done via the IPython console anddocker
Python package).Are they all running in the same container?
No, each is running in a separate container (via
<"docker-container-representation"> = cli.containers.run(...)
for all:roscore
,publisher
,rostopic
,subscriber
). But they share the same host network. (This was usually sufficient to enable cross-container ROS node communication.)