0

I was trying to build ROS with ardupilot.

RUN  sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' 
#RUN  sh -c 'echo "deb http://packages.ros.org/ros/ubuntu bionic main" > /etc/apt/sources.list.d/ros-latest.list'
RUN  apt install curl
RUN  curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add -
RUN  apt update
RUN  apt install ros-melodic-desktop-full  -y
RUN  apt search ros-melodic
 RUN echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
 RUN  source ~/.bashrc

When I built that;

CACHED [54/71] RUN echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc                   0.0s
ERROR [55/71] RUN  source ~/.bashrc                                                         0.4s
# ------
[55/71] RUN  source ~/.bashrc:
##0 0.332 /bin/sh: 1: source: not found
# ------
Dockerfile:87
# --------------------
85 |     
86 |     RUN echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
87 | >>> RUN  source ~/.bashrc
88 |     #RUN  source /opt/ros/melodic/setup.bash
89 |     
# --------------------
ERROR: failed to solve: process "/bin/sh -c source ~/.bashrc" did not complete successfully: exit code: 127

this error is occuring.

What should I do to solve that error?

Arif Erol
  • 1
  • 1
  • 1
    `source` is a Bash command, not a `sh` command. Running this in `RUN` is utterly pointless anyway; the process will run and immediately exit, without changing anything in the environment of subsequent `RUN` commands. What are you actually hoping to accomplish? What's in the file and what should it do? – tripleee Apr 03 '23 at 12:53
  • If you are hoping to build a Bash environment for interactive use, the file needs to be sourced when you log in to the image, not while you are building it. – tripleee Apr 03 '23 at 12:55
  • The thing I actually want to ask is not exactly this. When I run the above commands in an Ubuntu container that I created myself, I can install the things I want. However, when I give these commands in the Dockerfile, I get a 'source not found' error. – Arif Erol Apr 03 '23 at 13:44
  • Because `RUN` runs `sh`, not `bash`, like the error message and my first comment already says. Again, if you need actual help, you should [edit] to explain in more detail what you want this code to accomplish. All we can tell you with the information you provided so far is "don't do that." – tripleee Apr 03 '23 at 13:47
  • I've associated this question with a couple related to the problems @tripleee highlights (about `source` not being a standard shell command and `RUN source` being ineffective) and another more specific to the ROS setup script. – David Maze Apr 03 '23 at 14:24
  • I have edited it. I was trying to build ROS in my docker image. I added the lines which I started to build ROS. – Arif Erol Apr 04 '23 at 13:36

0 Answers0