我正在创建一个docker容器来执行ROS包。
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"
此安装脚本可能比调试尝试所需的要膨胀一些,目前看起来像这样:
#!/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
一切似乎都很好,直到最后一个命令失败为止
./setupROS.sh: line 10: catkin_make: command not found
如果我在shellscript中注释掉了最后一个命令,则仅自动运行前面的指令,然后打开一个交互式 session (docker run -it)并手动运行此catkin_make,它可以正常工作。
我是否在这一行中包含DEBIAN_FRONTEND变量都没有区别。
当在从Dockerfile调用的脚本中运行而不是手动运行时,catkin_make失败可能是什么原因?
最佳答案
以我的经验,当我们运行行源catkin_make
时,/opt/ros/melodic/setup.bash
被添加到路径中。通常,此行在安装结束时添加到.bashrc
中。也许您在其中运行脚本的环境不会继承相同的PATH
(类似于以sudo运行事物时)。我建议只将source /opt/ros/melodic/setup.bash
行添加到脚本中,看看是否有帮助。
关于bash - 从Dockerfile和脚本调用时ROS命令不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54990453/