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

How to RUN rosdep init and update in Dockerfile

asked 2016-08-04 15:12:21 -0600

spmaniato gravatar image

updated 2016-08-04 16:35:03 -0600

What's the correct way of running sudo rosdep init followed by rosdep update in a Dockerfile?

Looking at OSRF's indigo-ros-core Dockerfile, there's a simple:

RUN rosdep init \
    && rosdep update

However, running rosdep update like that in my own Dockerfile results in a warning, since it was essentially run with sudo. In turn, this results in rosdep install not finding dependencies later on.

So, since I'll be running this Docker image on a Raspberry Pi 3, I've been trying the Docker-raspbian-ros-indigo Dockerfile, which sets up a new user, pi, and then runs the rosdep commands as that user (see link for details).

USER pi
RUN sudo rosdep init
RUN rosdep update

But trying to build my Dockerfile like that gives me the following error message:

Step 12 : RUN sudo rosdep init
---> Running in d10888b83a25
sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges?

I also tried the trick from osblinnikov/ros-docker. In a nutshell:

RUN adduser --gecos "ROS User" --disabled-password ros
RUN usermod -a -G dialout ros
USER ros
RUN HOME=/home/ros rosdep update
# ...
RUN rosdep install --from-paths src --ignore-src --rosdistro $ROS_DISTRO -y

However, the rosdep install commands fails with:

Step 20 : RUN rosdep install --from-paths src --ignore-src --rosdistro $ROS_DISTRO -y
 ---> Running in 3be8cdf3c72a
sudo: no tty present and no askpass program specified
ERROR: the following rosdeps failed to install
  apt: command [sudo -H apt-get install -y python-mock] failed
executing command [sudo -H apt-get install -y python-mock]
The command '/bin/sh -c rosdep install --from-paths src --ignore-src --rosdistro $ROS_DISTRO -y' returned a non-zero code: 1

Update: This last error was resolved by:

  • letting the ros user execute commands as sudo without password (ros ALL=(ALL) NOPASSWD: ALL)
  • and also adding RUN sudo apt-get update before rosdep install in order to update the package lists
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2016-08-04 16:33:16 -0600

tfoote gravatar image

If you're doing all of this in the Dockerfile it's recommended to run everything as root.

There's no point in changing the user to pi then using sudo to run the command with super user privlages. You only want to drop into the pi user shortly before you finish the Dockerfile and provide the entrypoint.

edit flag offensive delete link more

Comments

1

Thanks for the quick reply Tully. So, I guess it's OK to ignore Warning: running 'rosdep update' as root is not recommended. in a Dockerfile? Looks like it worked so no complaints here :-)

spmaniato gravatar image spmaniato  ( 2016-08-04 17:17:41 -0600 )edit
3

If you run rosdep update as root only root will have access to the database. This is typically a problem if people run sudo rosdep update then try to run rosdep install at which time root has the db, but the USER does not. In this case you are going to run rosdep install as root. So it's fine.

tfoote gravatar image tfoote  ( 2016-08-04 18:01:55 -0600 )edit
0

answered 2022-11-14 21:52:35 -0600

ThomasL624 gravatar image

I know its not appropriate to ask question instead of answering the question, however I am facing the exact same issue with you right now. I got two image: (1)ros2 image and (2) autoware image.

The first ros2 image was built under root, nothing special here... and the problem is the second image: as the second image require volume mounting and root user is not ideal, thus I created a user ros with uid=1000 gid=1000 and sudo no-password and user it as a default user in image#2 by USER ros, and ENV /home/ros

When building the autoware project, I need to git clone their repo first before build (git remote is also needed thus no root user is best fit). I run rosdep update and rosdep install without sudo. Til this point, everything is still looking fine...

So at the last part, I have to colcon build and error occur.... it is telling that some basic packages like ament_cmake_coreConfig not found.

I have searched some thread talking about giving write permission but not sure which file should I give. Should I just rebuild the ros without root?

updated cache in /home/ros/.ros/rosdep/sources.cache <-- this is the output of rosdep update

edit flag offensive delete link more

Comments

well, I run printenv | grep ROS and some ROS_VERSION is missed, thus i source it again, and colcon build is fine.

ThomasL624 gravatar image ThomasL624  ( 2022-11-15 00:24:48 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2016-08-04 15:12:21 -0600

Seen: 5,070 times

Last updated: Nov 14 '22