gpt4 book ai didi

docker - 无法在Dockerfile中使用* RUN *执行* catkin *命令

转载 作者:行者123 更新时间:2023-12-02 18:10:39 24 4
gpt4 key购买 nike

我想在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

令人惊讶的是,如果我将CMD更改为catkin命令的RUN模式,则可以成功构建,即以下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环境(默认情况下,Docker使用sh执行命令)。这些命令对我有用:

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

关于docker - 无法在Dockerfile中使用* RUN *执行* catkin *命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55941916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com