0
$\begingroup$

Rosanswers logo

Hello,

I am creating a dockerfile for creating automatically an Ubuntu 16.04 operation system on which ROS kinetic is installed.

Until now, my the building process of the dockerfile yields to the installation of Ubuntu 16.04 as well as ROS kinetic. Unfortunately, the RUN catkin_make command inside inside of the dockerfile is not working in the building process, even executing the command RUN /bin/bash -c "bash /ros_entrypoint.sh" beforehand.

However, when I run the resulting docker image ( sudo docker run -it <its hash-number> ) and execute $bash /ros_entrypoint.sh && cd ~/catkin_ws/ && catkin_make in the Ubuntu shell, the catkin_make is working as you can see in the following image:

https://i.imgur.com/WcwHigJ.png

My goal is to achieve the same result with the building process of a dockerfile. I am out of ideas, how I could achieve this. Therefore I am asking for help.

I have already tried the answers of other questions, dealing with the almost same issue:

https://stackoverflow.com/questions/20635472/using-the-run-instruction-in-a-dockerfile-with-source-does-not-work/25998432#25998432

https://answers.ros.org/question/241834/extendingsourcing-the-ros-install-dir-in-a-dockerfiles-build-phase/

https://github.com/ros-planning/moveit/blob/fd835d142e0571da7bfd4649e6bda8a015a0d8f8/.docker/source/Dockerfile#L27-L29

The current dockerfile, which needs to be improved, looks currently like this:

FROM ubuntu:16.04
FROM osrf/ros:kinetic-desktop-full

#### HACK, replacing shell with bash for later docker build commands
RUN mv /bin/sh /bin/sh-old && \
ln -s /bin/bash /bin/sh

RUN /bin/bash -c "bash /ros_entrypoint.sh"

RUN mkdir -p ~/catkin_ws/src/

RUN cd ~/catkin_ws/ && \
catkin_make

Originally posted by Daniel_1337 on ROS Answers with karma: 81 on 2019-01-12

Post score: 3


Original comments

Comment by jayess on 2019-01-12:
Please don't use an image to display text. Images are not searchable and people cannot copy and paste the text from the image. Please update your question with a copy and paste of the text.

Comment by Daniel_1337 on 2019-01-12:
@jayess: The picuture is not important. It just shows that the commands(bash /ros_entrypoint.sh && cd ~/catkin_ws/ && catkin_make) are working, when I run the dockerfile.

Comment by dj95 on 2020-04-28:
Hello, I'm a beginner trying to understand Docker. Could someone explain what does replacing shell with bash actually do?

#### HACK, replacing shell with bash for later docker build commands
RUN mv /bin/sh /bin/sh-old && \
ln -s /bin/bash /bin/sh
$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

You dockerfile is a bit erratic, so I'll just provide a complete minimal example of building a ROS 1 package from source. Just swap melodic for kinetic if that is the distro you still require; the following includes:
Cloning source code into workspace
Installing package dependencies
Building package using catkin tools
Sourcing workspace into entrypoint
And launching package nodes

FROM ros:melodic

# install build tools
RUN apt-get update && apt-get install -y \
      python-catkin-tools \
    && rm -rf /var/lib/apt/lists/*

# clone ros package repo
ENV ROS_WS /opt/ros_ws
RUN mkdir -p $ROS_WS/src
WORKDIR $ROS_WS
RUN git -C src clone \
      -b $ROS_DISTRO-devel \
      https://github.com/ros/ros_tutorials.git

# install ros package dependencies
RUN apt-get update && \
    rosdep update && \
    rosdep install -y \
      --from-paths \
        src/ros_tutorials/roscpp_tutorials \
      --ignore-src && \
    rm -rf /var/lib/apt/lists/*

# build ros package source
RUN catkin config \
      --extend /opt/ros/$ROS_DISTRO && \
    catkin build \
      roscpp_tutorials

# source ros package from entrypoint
RUN sed --in-place --expression \
      '$isource "$ROS_WS/devel/setup.bash"' \
      /ros_entrypoint.sh

# run ros package launch file
CMD ["roslaunch", "roscpp_tutorials", "talker_listener.launch"]

Originally posted by ruffsl with karma: 1094 on 2019-01-14

This answer was NOT ACCEPTED on the original site

Post score: 4


Original comments

Comment by Daniel_1337 on 2019-01-14:
thank you for your response. Unfortunately, you do not answer the question how one can execute a catkin_make command.

Comment by ruffsl on 2019-01-14:
As catkin_make doesn't have the same --extend argument to Explicitly Specifying Workspace Chaining, I elected show you how to catkin build without resorting to swapping the shell.

Comment by dj95 on 2020-04-28:
What does && rm -rf /var/lib/apt/lists/* do? Why is it required?

Comment by ruffsl on 2020-04-29:
delete all the apt list files since they're big and get stale quickly

Comment by vvdy on 2021-09-09:
I realise this is an old post, but I just wanted to say thank you for this extensive and clear example! It was incredibly helpful in making my own first docker images.

Comment by vyke2 on 2022-02-20:
Thanks! very helpful.

$\endgroup$
0
$\begingroup$

Rosanswers logo

In order to be able to execute a catkin_make command one can use the following command:

RUN /bin/bash -c '. /opt/ros/kinetic/setup.bash; cd <into the desired folder e.g. catkin_ws>; catkin_make'

Thus, the working dockerfile looks like this:

FROM osrf/ros:kinetic-desktop-full

# ...
# do what you need to do for example git clone something into ~/catkin_ws/src
# ...

RUN /bin/bash -c '. /opt/ros/kinetic/setup.bash; cd <into the desired folder e.g. ~/catkin_ws/src>; catkin_make'

Originally posted by Daniel_1337 with karma: 81 on 2019-01-14

This answer was NOT ACCEPTED on the original site

Post score: 5


Original comments

Comment by wthwlh on 2019-05-02:
Ty this works for me. I wonder why

RUN /bin/bash -c /opt/ros/kinetic/setup.bash \
        && catkin_make 

doesn't work. It is the same layer of container and using same tty. Do you know why it has to be written like that?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.