Unable to execute *catkin* commands using *RUN* in Dockerfile Unable to execute *catkin* commands using *RUN* in Dockerfile docker docker

Unable to execute *catkin* commands using *RUN* in Dockerfile


Your second case will build because CMD is not executed during the build. It simply defines the default command to execute when starting the container. See the docker CMD docs for more information.

The root of your problem is that ~/.bashrc is not being called in the shell used by the RUN instruction. As a result, the environment variables are not present to allow catkin_make or other ros commands to work. I address this issue in my images by running a command similar to the below.

RUN . /opt/ros/kinetic/setup.sh && \    catkin_make

You will need to activate the environment in each RUN instruction that needs those environment variables because the shell is not re-used between RUN commands.

Edited to include the improvement from David Maze.


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-robotRUN echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrcRUN mkdir -p /home/catkin_ws/srcWORKDIR /home/catkin_ws/src#RUN /opt/ros/indigo/bin/catkin_init_workspaceRUN /bin/bash -c '. /opt/ros/indigo/setup.bash; catkin_init_workspace /home/catkin_ws/src'WORKDIR /home/catkin_wsRUN /bin/bash -c '. /opt/ros/indigo/setup.bash; cd /home/catkin_ws; catkin_make'RUN echo "source /home/catkin_ws/devel/setup.bash" >> ~/.bashrc