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

catkin_make command not found executing by a dockerfile

asked 2019-01-12 09:36:18 -0500

Daniel_1337 gravatar image

updated 2019-01-12 14:48:20 -0500


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 /" beforehand.

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

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:

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 /"

RUN mkdir -p ~/catkin_ws/src/

RUN cd ~/catkin_ws/ && \
edit retag flag offensive close merge delete



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.

jayess gravatar image jayess  ( 2019-01-12 13:51:21 -0500 )edit

@jayess: The picuture is not important. It just shows that the commands(bash / && cd ~/catkin_ws/ && catkin_make) are working, when I run the dockerfile.

Daniel_1337 gravatar image Daniel_1337  ( 2019-01-12 14:45:56 -0500 )edit

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
dj95 gravatar image dj95  ( 2020-04-28 10:10:54 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2019-01-14 16:10:03 -0500

Daniel_1337 gravatar image

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'
edit flag offensive delete link more


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?

wthwlh gravatar image wthwlh  ( 2019-05-02 16:41:40 -0500 )edit

answered 2019-01-14 15:27:08 -0500

ruffsl gravatar image

updated 2019-01-14 15:31:27 -0500

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
RUN git -C src clone \
      -b $ROS_DISTRO-devel \

# 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 \

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

# run ros package launch file
CMD ["roslaunch", "roscpp_tutorials", "talker_listener.launch"]
edit flag offensive delete link more


thank you for your response. Unfortunately, you do not answer the question how one can execute a catkin_make command.

Daniel_1337 gravatar image Daniel_1337  ( 2019-01-14 15:55:36 -0500 )edit

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.

ruffsl gravatar image ruffsl  ( 2019-01-14 17:48:15 -0500 )edit

What does && rm -rf /var/lib/apt/lists/* do? Why is it required?

dj95 gravatar image dj95  ( 2020-04-28 10:33:20 -0500 )edit

delete all the apt list files since they're big and get stale quickly

ruffsl gravatar image ruffsl  ( 2020-04-29 22:25:45 -0500 )edit

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.

vvdy gravatar image vvdy  ( 2021-09-09 11:16:25 -0500 )edit

Thanks! very helpful.

vyke2 gravatar image vyke2  ( 2022-02-20 11:07:57 -0500 )edit

Question Tools

1 follower


Asked: 2019-01-12 09:21:23 -0500

Seen: 10,093 times

Last updated: Jan 14 '19