Ask Your Question
0

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
2

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

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

Seen: 267 times

Last updated: Jan 29 '21