I want to use a customized ros-indigo on docker. I prepared the following Dockerfile
FROM ros:indigo-robot
RUN echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc
RUN mkdir -p /home/catkin_ws/src
WORKDIR /home/catkin_ws/src
RUN catkin_init_workspace
WORKDIR /home/catkin_ws
RUN catkin_make
RUN echo "source /home/catkin_ws/devel/setup.bash" >> ~/.bashrc
However, it throws me an error at both RUN catkin_init_workspace and RUN catkin_make that says
/bin/sh: catkin_make: command not found
The command '/bin/sh -c catkin_init_workspace' returned a non-zero code: 127
Surprisingly, it builds succesfully if I change RUN with CMD for catkin commands, i.e. the following Dockerfile builds just fine
RUN echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc
RUN mkdir -p /home/catkin_ws/src
WORKDIR /home/catkin_ws/src
CMD catkin_init_workspace
WORKDIR /home/catkin_ws
CMD catkin_make
RUN echo "source /home/catkin_ws/devel/setup.bash" >> ~/.bashrc
What is more surprising is these catkin commands work perfectly on a container that is built separately on top of any ros-indigo image.
This clearly indicates that either RUN is not an appropriate way to invoke catkin commands or I am invoking it incorrectly.
Now, given that the nature of CMD command is different from the RUN command, it does not make sense to use it in my case. Hence, I shall appreciate if someone can point me out the right way to do so.
You need to setup a proper bash environment for the commands to work (by default Docker uses sh to execute commands). These commands worked for me:
FROM ros:indigo-robot
RUN echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc
RUN mkdir -p /home/catkin_ws/src
WORKDIR /home/catkin_ws/src
#RUN /opt/ros/indigo/bin/catkin_init_workspace
RUN /bin/bash -c '. /opt/ros/indigo/setup.bash; catkin_init_workspace /home/catkin_ws/src'
WORKDIR /home/catkin_ws
RUN /bin/bash -c '. /opt/ros/indigo/setup.bash; cd /home/catkin_ws; catkin_make'
RUN echo "source /home/catkin_ws/devel/setup.bash" >> ~/.bashrc