gpt4 book ai didi

Docker-compose 找不到包

转载 作者:行者123 更新时间:2023-12-05 05:49:42 27 4
gpt4 key购买 nike

当我尝试运行 docker-compose up 以运行 2 个 ROS noetic 容器时,未运行 roscore 的容器无法找到该包。

master容器用于运行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

当命令 docker-compose up 完成时记录:

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

最佳答案

运行时运行你的包之前尝试应用你的setup.bash,假设你的工作空间在/home/user/Projects/catkin_ws在 docker 镜像中,在你的 docker-compose 文件中尝试以下命令,

command: ["bash", "-c", "source /home/user/Projects/catkin_ws/devel/setup.bash && rosrun sadrifung6 pilot.py"]

注意:上述setup.bash在Dockerfile(image build stage)和docker-compose(运行时).

关于Docker-compose 找不到包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70627825/

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