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

How to source setup.bash in a ROS2 Dockerfile?

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

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

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

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

Finally, a simple solution that works for me is

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

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

edit flag offensive delete link more

Question Tools



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

Seen: 2,234 times

Last updated: Jan 29 '21