Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker-compose wont find package

When I try to run docker-compose up to run 2 ROS noetic containers the package couldn't be found by the container not running roscore.

The master container is used to run roscore and the piloot container to run a python script in a catkin package.

The catkin package is imported trough a external project folder which get imported in the dockerfile. catkin_make is also done in the 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

log when command docker-compose up is done:

Starting master ... done
Starting piloot ... done
Attaching to master, piloot
piloot    | [rospack] Error: package 'sadrifung6' not found
piloot exited with code 2

dockerfile used for both containers:

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

like image 271
JoranNuyts Avatar asked Jun 22 '26 04:06

JoranNuyts


1 Answers

Try applying your setup.bash before running your package at runtime, assume your workspace is under /home/user/Projects/catkin_ws in docker image, try the following command in your docker-compose file,

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

Notice: the difference of applying the above setup.bash in Dockerfile (image build stage) and docker-compose (runtime).

like image 186
balun Avatar answered Jun 26 '26 16:06

balun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!