Integrating ROS with docker
$ docker build --tag ros-docker . $ docker run -it ros-dockerThe demo application consist in an executable that publishes keys strokes pressed (key_publisher.py) and another executable that reads those published keys (keys_to_twist.py) and transform them into velocity commands.
First a docker network must be created, run:
$ docker network create ros_netNext, roscore must be initialized, run:
$ docker run -it --rm --net ros_net --name master --env ROS_HOSTNAME=master ros:melodic roscore Now, the desired applications can be run as following:
Key publisher:
$ docker run -it --rm --net ros_net --name key_publisher --env ROS_HOSTNAME=key_publisher --env ROS_MASTER_URI=http://master:11311 ros-docker rosrun keyboard_driver key_publisher.py Key to twist:
$ docker run -it --rm --net ros_net --name keys_to_twist --env ROS_HOSTNAME=keys_to_twist --env ROS_MASTER_URI=http://master:11311 ros-docker rosrun keyboard_driver keys_to_twist.py If you want to inspect the data being exchange by ros you can run another container without running any commands, as follows:
$ docker run -it --rm --net ros_net --name echo --env ROS_HOSTNAME=echo --env ROS_MASTER_URI=http://master:11311 ros:melodicThen run rostopic, rosmsg etc.
Run a package that is located in you computer in the ros container
RUN catkin_create_pkg YOUR_PACKAGE_NAME
COPY PACKAGE_LOCATION_ON_YOUR_COMPUTER /catkin_ws/src/YOUR_PACKAGE_NAME
$ docker run -it ros-docker rosrun YOUR_PACKAGE_NAME EXECUTABLE
Check the Run Demo Application section for an example on how to run a full application.
More information about running: https://hub.docker.com/r/library/ros/