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

Connection refused - docker to docker

asked 2019-03-29 09:35:14 -0600

kk2105 gravatar image

updated 2019-04-06 18:32:35 -0600

jayess gravatar image


I am trying to establish ros connection between 2 dockers. Details given below.

  1. Lets consider I have docker_1 and docker_2.

  2. I am able to publish message from docker_1 and subscribe it to docker_2 provided my roscore is running in docker_1.

  3. When I try to publish message from docker_2 and subscribe it from docker_1 I am getting the below error.


[ERROR] [WallTime: 1553869754.845807] Unable to connect subscriber to publisher [] for topic [/check]: unable to requestTopic: [Errno 111] Connection refused

IP details:

 docker_1 : 
 docker_2 : 

Could you please help me to fix this.

Thank you, KK

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-03-30 11:29:58 -0600

letsbelopez gravatar image

Can you post your Docker file and/or your docker-compose.yml file?

Some things to consider:

  • Are the containers communicating through the host OS?
  • Or are you using a docker bridge network?
  • Have you exposed the appropriate ports using Docker?
edit flag offensive delete link more


Thanks for the answer. Please find the response below: Are the containers communicating through the host OS? - No Or are you using a docker bridge network? - No Have you exposed the appropriate ports using Docker? - Yes

kk2105 gravatar image kk2105  ( 2019-04-03 21:58:10 -0600 )edit

If you're not using a bridge network, I think they must be using the host OS or how else would the containers be able to communicate?

Can you edit your question and post the Docker file and the docker-compose.yml file if you have one or link to your code.

letsbelopez gravatar image letsbelopez  ( 2019-04-04 23:53:09 -0600 )edit

@letsbelopez Thanks for the reply. I was able to establish the communication by following the below steps:

docker_1 : 
ROS_MASTER_URI = http://docker_1_IP:11311
ROS_IP = docker_1_IP

docker_2 : 
ROS_MASTER_URI = http://docker_1_IP:11311
ROS_IP = docker_2_IP

Dockers where able to communicate, however if I have to send msg from docker 2 to 1, subscriber in the docker 1 needs to be started first. Is this the right way to do ?

kk2105 gravatar image kk2105  ( 2019-04-05 04:53:47 -0600 )edit

It looks like you followed similar instructions to running ROS on two machines The two docker containers are sharing the same ros master, and are now able to communicate. The way ROS is built, it should not matter what node (publisher or subscriber) is started first. However, the subscriber will miss all messages sent before it was started. There are more nuances to this but this is the basic use case.

letsbelopez gravatar image letsbelopez  ( 2019-04-05 09:53:28 -0600 )edit

@letsbelopez Could you help me with the better ways to do this if any. Also I have tried sending the message from slave to master, if I start the subscriber in the master after the publisher in the slave, I do not see any message being received in master end.

kk2105 gravatar image kk2105  ( 2019-04-07 23:51:16 -0600 )edit

Question Tools



Asked: 2019-03-29 09:35:14 -0600

Seen: 1,302 times

Last updated: Apr 06 '19