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

ROS (Melodic) + Docker: rosrun not found

asked 2020-04-22 03:32:35 -0500

Julian98 gravatar image

updated 2020-04-22 03:34:44 -0500

Hi there,

I am currently trying to run ROS Melodic on Docker to build the rosserial_arduino libraries for Arduino. Therefore I need to run rosrun rosserial_arduino make_libraries.py in the Docker container. However I get a rosrun: command not found, despite sourcing the setup.bash. Here is my Dockerfile:

FROM osrf/ros:melodic-desktop-full-bionic as builder_base
SHELL ["/bin/bash", "-c"]
COPY . .
RUN apt-get update && apt-get install -y \
    ros-melodic-rosserial-arduino \
    ros-melodic-rosserial \
    python-rosdep \
    python-rosinstall \
    python-rosinstall-generator \
    python-wstool \
    build-essential \
    && rm -rf /var/lib/apt/lists/

RUN echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
RUN source ~/.bashrc
WORKDIR /arduino
RUN rosrun rosserial_arduino make_libraries.py

I run this on Ubuntu 19.04.

Any ideas why I get this error and how to solve it?

Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-04-22 03:46:55 -0500

gvdhoorn gravatar image

updated 2020-04-22 03:53:21 -0500

In Docker, all RUN statements are executed in a separate shell (this is not entirely correct, but it gets the point across). So source in one RUN statement does not affect the environment in which another is run.

RUN source ~/.bashrc

You can do this, but you'll need to run this in bash, otherwise it won't work (something like bash -c 'source ...').

But I believe there is an easier way to do this:

RUN /opt/ros/melodic/env.sh rosrun rosserial_arduino make_libraries.py

The env.sh script takes care of loading all the required environment variables.

I would also recommend to use relative paths as little as possible, as they may not resolve to where you expect them to resolve to in Docker builds.

edit flag offensive delete link more

Comments

1

PS: technically this isn't really a ROS problem, but caused by the way Docker (builds) work(s).

gvdhoorn gravatar image gvdhoorn  ( 2020-04-22 03:52:17 -0500 )edit
1

Thank you very much! It is indeed, but I think it might be helpful for other people working with ROS to have it answered in this forum.

Julian98 gravatar image Julian98  ( 2020-04-22 14:44:23 -0500 )edit

Question Tools

Stats

Asked: 2020-04-22 03:32:35 -0500

Seen: 1,602 times

Last updated: Apr 22 '20