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

No rostopic response when run in docker container

asked 2018-05-03 08:39:27 -0500

thinwybk gravatar image

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'
edit retag flag offensive close merge delete

Comments

This looks like the output of an IPython console. Is this what you mean with "manually running"?

gvdhoorn gravatar image gvdhoorn  ( 2018-05-03 09:03:38 -0500 )edit

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:

❯ rostopic hz /topic_to_observe
subscribed to [/topic_to_observe]
average rate: 1.000
    min: 1.000s max: 1.000s std dev: 0.00000s windo
thinwybk gravatar image thinwybk  ( 2018-05-03 09:29:13 -0500 )edit

... I expected to get something similar with In [6]: rostopic.logs() Out[6]: ''.

thinwybk gravatar image thinwybk  ( 2018-05-04 02:23:24 -0500 )edit

I'm not sure I understand what you're asking, but that is probably just me.

gvdhoorn gravatar image gvdhoorn  ( 2018-05-04 03:24:17 -0500 )edit

Sorry, probably not clear enough: When I run roscore, a publisher node and rostopic hz I would expect the same output of rostopic hz when (a) I run them on Ubuntu directly or (b) I run them inside Docker containers (like done via the IPython console and docker Python package).

thinwybk gravatar image thinwybk  ( 2018-05-04 03:33:06 -0500 )edit

Are they all running in the same container?

gvdhoorn gravatar image gvdhoorn  ( 2018-05-04 03:33:50 -0500 )edit

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.)

thinwybk gravatar image thinwybk  ( 2018-05-04 03:37:00 -0500 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2018-05-04 03:43:15 -0500

gvdhoorn gravatar image

updated 2018-05-04 05:43:06 -0500

Yeah, I just noticed the host bit. That should work, so not sure. I've never really extensively used the Docker Python libs. Perhaps it's doing something strange with TTYs?

A quick google led me to docker/docker-py/issues/390.

Notice the tty=True argument there.

edit flag offensive delete link more

Comments

Thanks for that hint. It's not urgent right now. I'll have a look at this as soon as I can spend time on it and keep the question open for now.

thinwybk gravatar image thinwybk  ( 2018-05-04 04:29:19 -0500 )edit
2

Thx. Changing to rostopic = cli.containers.run(image='osrf/ros:indigo-desktop-trusty', network='host', command='rostopic hz /topic_to_observe', detach=True, tty=True) solved this issue.

thinwybk gravatar image thinwybk  ( 2018-05-04 05:41:40 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2018-05-03 08:39:27 -0500

Seen: 1,274 times

Last updated: May 04 '18