我想在 Docker 上使用定制的 ros-indigo。我准备了以下 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
然而,在RUN catkin_init_workspace和RUN catkin_make处,它向我抛出一个错误,提示为:
/bin/sh: catkin_make: command not found
The command '/bin/sh -c catkin_init_workspace' returned a non-zero code: 127
令人惊讶的是,如果我将RUN更改为CMD以在catkin命令中运行,则可以成功构建,也就是说,以下Dockerfile可以正常构建
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
更令人惊讶的是,这些catkin命令在任何ros-indigo镜像之上构建的容器中都可以完美运行。
这明确表明,使用RUN来调用catkin命令可能不是合适的方式,或者我正在错误地调用它。
现在,考虑到CMD命令的性质与RUN命令不同,在我的情况下使用它没有意义。因此,如果有人能指出正确的做法,我将不胜感激。
.
命令而不是 bash 的source
扩展命令,则它将在所有 Bourne 兼容的 shell 中工作,包括 Busybox 和 Alpine 基础镜像中的最小 shell,并且您无需设置SHELL
。 - David MazeFROM ros:indigo-robot
RUN apt-get update && apt-get install -y build-essential
RUN mkdir -p /home/catkin_ws/src
RUN . /opt/ros/indigo/setup.sh && catkin_init_workspace /home/catkin_ws/src
RUN . /opt/ros/indigo/setup.sh && cd /home/catkin_ws && catkin_make
RUN echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc
- Sanjay