当我试图运行docker-组合来运行2个ROS符号容器时,没有运行roscore的容器找不到包。
主容器用于运行roscore,piloot容器用于在catkin包中运行python脚本。
catkin包是通过外部项目文件夹导入的,该文件夹被导入到dockerfile中。catkin_make也在dockerfile中完成。
docker-compose.yml
version: "2.1"
services:
master:
image: sadrifun_master:latest
container_name: master
hostname: master
environment:
- "ROS_HOSTNAME=master"
command: roscore
piloot:
image: sadrifun_pilot:latest
container_name: piloot
hostname: piloot
environment:
- "ROS_HOSTNAME=piloot"
- "ROS_MASTER_URI=http://master:11311"
command: rosrun sadrifung6 pilot.py
depends_on:
- master当命令停靠-组合完成时记录如下:
Starting master ... done
Starting piloot ... done
Attaching to master, piloot
piloot | [rospack] Error: package 'sadrifung6' not found
piloot exited with code 2用于两个容器的dockerfile:
FROM osrf/ros:noetic-desktop-full-focal
# The OSRF ROS Noetic containers use the root user.
# Therefore, the following commands are executed as root up until the
# USER user statement.
# We love UTF!
ENV LANG C.UTF-8
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
# Set the nvidia container runtime
ENV NVIDIA_VISIBLE_DEVICES \
${NVIDIA_VISIBLE_DEVICES:-all}
ENV NVIDIA_DRIVER_CAPABILITIES \
${NVIDIA_DRIVER_CAPABILITIES:+$NVIDIA_DRIVER_CAPABILITIES,}graphics
# Install some handy tools.
RUN set -x \
&& apt-get update \
&& apt-get --with-new-pkgs upgrade -y \
&& apt-get install -y mesa-utils \
&& apt-get install -y iputils-ping \
&& apt-get install -y apt-transport-https ca-certificates \
&& apt-get install -y openssh-server python3-pip exuberant-ctags \
&& apt-get install -y git vim tmux nano htop sudo curl wget gnupg2 \
&& apt-get install -y bash-completion \
&& apt-get install -y libcanberra-gtk3-0 \
&& apt-get install -y ros-noetic-turtlebot3 \
&& apt-get install -y ros-noetic-turtlebot3-bringup ros-noetic-turtlebot3-description \
&& apt-get install -y ros-noetic-turtlebot3-simulations \
&& apt-get install -y ros-noetic-rviz \
&& pip3 install powerline-shell \
&& rm -rf /var/lib/apt/lists/* \
&& useradd -ms /bin/bash user \
&& echo "user:user" | chpasswd && adduser user sudo \
&& echo "user ALL=(ALL) NOPASSWD: ALL " >> /etc/sudoers
# The OSRF contianer didn't link python3 to python, causing ROS scripts to fail.
RUN ln -s /usr/bin/python3 /usr/bin/python
USER user
WORKDIR /home/user
RUN sudo usermod -a -G video user
RUN git clone https://github.com/jimeh/tmux-themepack.git ~/.tmux-themepack \
&& git clone https://github.com/tmux-plugins/tmux-resurrect ~/.tmux-resurrect
COPY --chown=user:user ./.tmux.conf /home/user/.tmux.conf
COPY --chown=user:user ./.powerline.sh /home/user/.powerline.sh
RUN mkdir -p /home/user/.vim/bundle \
&& git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
COPY --chown=user:user ./.vimrc /home/user/.vimrc
RUN set -x \
&& vim -E -u NONE -S /home/user/.vimrc -C "+PluginInstall" -C "+qall"; exit 0
#
RUN rosdep update \
&& echo "source /opt/ros/noetic/setup.bash" >> /home/user/.bashrc
RUN mkdir -p Projects/catkin_ws/src
RUN /bin/bash -c '. /opt/ros/noetic/setup.bash; cd /home/user/Projects/catkin_ws; catkin_make'
RUN echo "source /home/user/Projects/catkin_ws/devel/setup.bash --extend" >> /home/user/.bashrc
STOPSIGNAL SIGTERM
CMD sudo service ssh start && /bin/bash发布于 2022-01-09 09:33:37
在运行时setup.bash运行包之前尝试应用您的/home/user/Projects/catkin_ws,假设您的工作区位于/home/user/Projects/catkin_ws中的/home/user/Projects/catkin_ws中,尝试在您的docker -复合文件中执行以下命令,
command: ["bash", "-c", "source /home/user/Projects/catkin_ws/devel/setup.bash && rosrun sadrifung6 pilot.py"]注意:上述setup.bash在Dockerfile (映像构建阶段)和Dockerfile(运行时)中应用的区别。
https://stackoverflow.com/questions/70627825
复制相似问题