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

How to source setup.bash in a ROS2 Dockerfile?

asked 2021-01-27 09:32:33 -0500

updated 2021-01-28 14:13:28 -0500

It seems that sourcing setup.bash in a ros2 dockerfile is not that easy. In particular,

RUN bash -c "source /opt/ros/${ROS_DISTRO}/setup.bash \ && echo ${AMENT_PREFIX_PATH}"

does not print anything although AMENT_PREFX_PATH got a value from setup.bash. I have to use the RUN [.., ..] syntax. Is there an easier way to do so?

FROM ros:eloquent 

#this one does not work    
RUN bash -c "source /opt/ros/${ROS_DISTRO}/setup.bash \
        &&  echo ${AMENT_PREFIX_PATH}"

#this one works, printing /opt/ros/eloquent
RUN ["/bin/bash", "-c", "source /opt/ros/${ROS_DISTRO}/setup.bash &&  echo ${AMENT_PREFIX_PATH}"]
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2021-01-29 00:26:59 -0500

Finally, a simple solution that works for me is

RUN . /opt/ros/${ROS_DISTRO}/setup.sh && other_commands

That is, use "." instead of "source", and use "setup.sh" instead of "setup.bash".

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2021-01-27 09:32:33 -0500

Seen: 2,388 times

Last updated: Jan 29 '21