Skip to content

Communicating between ros services in docker-compose #12

@nicholasadr

Description

@nicholasadr

Sometimes it might be desirable to run multiple ros nodes in separate docker containers. The following docker-compose file shows how we can do so.

Some note:

  • There are two separate Dockerfiles for each service (ros-server and ros-client) contained in separate directory ./server/ and ./client/ as indicated in context
  • We created a custom network in order to assign static IPs to each container. This way, we can assign $ROS_IPs and point client's $ROS_MASTER_URI towards the server's IP that will start the rosmaster
  • In this case the ros server runs a Deep Learning server

docker-compose.yml example:

version: '2.3'
services:
  ros-server:
    networks:
      ros-network:
        ipv4_address: ${dSERVER_IP}
    image: ros-server:v1.0.0
    build:
      context: ./server
      args:
        user: ${dUSER}
        group: ${dGROUP}
        uid: ${dUID}
        gid: ${dGID}
    environment:
      - "ROS_IP=${dSERVER_IP}"
    user: "${dUID?err}:${dGID?err}"
    runtime: nvidia
    tty: true
    ports:
    - "${dJUPYTER_PORT?err}:8888"
    - "${dTENSORBOARD_PORT?err}:6006"
    volumes:
    - "${dDRIVE?err}:/data"
    - "${dWORKSPACE?err}:/home/${dUSER}/workspace"
  ros-client:
    networks:
      ros-network:
        ipv4_address: ${dCLIENT_IP}
    image: ros-client:v1.0.0
    build:
      context: ./client
      args:
        user: ${dUSER}
        group: ${dGROUP}
        uid: ${dUID}
        gid: ${dGID}
    environment:
      - "ROS_IP=${dCLIENT_IP}"
      - "ROS_MASTER_URI=http://${dSERVER_IP}:11311"
    user: "${dUID?err}:${dGID?err}"
    runtime: nvidia
    tty: true
    volumes:
    - "${dDRIVE?err}:/data"
    - "${dWORKSPACE?err}:/home/${dUSER}/workspace"

networks:
  ros-network:
    driver: bridge
    ipam:
      config:
        - subnet: 10.5.0.0/16
          gateway: 10.5.0.1

.env contains:

dSERVER_IP=10.5.0.5
dCLIENT_IP=10.5.0.6

References:

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions