Search code examples
bashdockerdockerfileros

ROS command not working when called from Dockerfile and script


I'm creating a docker container to execute a ROS package.

FROM ros:melodic
COPY . /rosdata
WORKDIR /rosdata
RUN rm /bin/sh && ln -s /bin/bash /bin/sh && chmod +x setupROS.sh && bash -c "./setupROS.sh"

This setup script is probably a bit more bloated than it needs to be from debugging attempts and currently looks like this:

#!/bin/sh
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y wget apt-utils
sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
wget https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -O - | apt-key add -
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y ros-melodic-pcl-conversions ros-melodic-pcl-ros
apt-get update
DEBIAN_FRONTEND=noninteractive rosdep install --as-root apt:false --from-paths src --ignore-src --rosdistro melodic -y
DEBIAN_FRONTEND=noninteractive catkin_make

Everything seems fine, until the last command fails with

./setupROS.sh: line 10: catkin_make: command not found

If I comment out this last command in the shellscript, only run the previous instructions automatically and then open an interactive session (docker run -it) and run this catkin_make by hand, it works as expected. Whether or not I include the DEBIAN_FRONTEND variable in this line makes no difference.

What could be the reason catkin_make fails when run in a script called from a Dockerfile, but not when run by hand?


Solution

  • In my experience, catkin_make is added to path when we run the line source /opt/ros/melodic/setup.bash. Typically this line is added to .bashrc at the end of installation. Maybe the environment you are running your script in doesn't inherit the same PATH (similar to when you run things as sudo). I'd suggest just adding the source /opt/ros/melodic/setup.bash line to your script and see if that helps.