ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Docker - Package not found even after source

asked 2021-06-23 10:10:59 -0600

Chris1343 gravatar image

updated 2022-04-30 13:21:12 -0600

lucasw gravatar image

I'm trying to launch rosbridge_server inside docker.

This is my docker file:

FROM ros:noetic

RUN apt-get update && apt-get install -y \ 
    ros-noetic-rosbridge-server \

RUN apt-get update && \
    rosdep update 

RUN apt-get update && apt-get install -y \
    lsof \
    python3-pip \

ADD ./my_workspace /my_workspace

RUN /bin/bash -c 'source /opt/ros/noetic/setup.bash; \
        cd /my_workspace; catkin_make; \
        source /my_workspace/devel/setup.bash; \
        rospack find my_package'    #"rospack find" successfully prints my package's path. 
                                    #No problem here

#RUN rospack find my_package           #Here is the problem.
                                #If I uncomment this, I get an error that rospack is not found. 
                                       #It's like nor the source command or my package 
                                       #exist outside the previous RUN command

CMD ["./launch_ros_bridge.bash"] #Ros bridge is started but once 
                                 #I subscribe to a topic of my package,
                                 #it prints an error that "my_package" is not found

This is my launch_ros_bridge.bash script:

roslaunch rosbridge_server rosbridge_websocket.launch

The error I receive when launch_ros_bridge.bash is executed, is

[-] [ERROR] [1624456872.953620]: [Client 0] advertise: Unable to import my_package.msg from package my_package. Caused by: No module named 'my_package'. [-] ROS path [0]=/opt/ros/noetic/share/ros [-] ROS path [1]=/opt/ros/noetic/share

Again, my package's path is not displayed.

My question is how can I successfully start and subscribe to ros bridge server inside a docker?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-06-23 18:41:10 -0600

404RobotNotFound gravatar image

Add the source /my_workspace/devel/setup.bash into the launch_ros_bridge.bash script before running the roslaunch command.

Sourcing the setup.bash script will basically setup some environment variables in your bash instance so ROS can find all of your packages. In general, each RUN command is a basically a new bash instance where the environment variables from previous runs are not preserved. Your comment is actually correct in the fact that your source command does not really matter outside of the previous run command.

So like when opening a new terminal, you need to re-source the workspace for every one even if you source it in a previous one.

edit flag offensive delete link more


You don't need to source at all. Just prefix the command you want to run with /my_workspace/devel/ That will take care of setting everything up and run your command.

gvdhoorn gravatar image gvdhoorn  ( 2021-06-24 02:18:46 -0600 )edit

As an example, you can also use the dot .directive in shell to source the ros envelopment without using bash:

ruffsl gravatar image ruffsl  ( 2021-07-06 12:05:00 -0600 )edit

Question Tools



Asked: 2021-06-23 10:10:59 -0600

Seen: 1,561 times

Last updated: Jun 23 '21