Create Dockerfile for ros2 package : ament_cmake error
Hello,
I try to use docker to develop ros2 packages. In this context, I use the minimal_publisher package from https://github.com/ros2/examples as example which has the structure:
minimal_publisher/
minimal_publisher/CMakeLists.txt
minimal_publisher/lambda.cpp
minimal_publisher/member_function.cpp
minimal_publisher/not_composable.cpp
minimal_publisher/package.xml
minimal_publisher/README.md
minimal_publisher/Dockerfile #THIS FILE WAS ADDED BY ME
You can find the complete minimum example package on https://github.com/DentOpt/minimal_publisher
"minimal_publisher/Dockerfile" is the following dockerfile that I added to use to colcon build the package in a ros2 workspace in a docker container:
FROM ros:crystal
# install ros build tools
RUN apt-get update \
&& apt-get install -y python3-colcon-common-extensions \
&& rm -rf /var/lib/apt/lists/*
# clone ros package repo
ENV ROS2_WS /home/ros2_ws
RUN mkdir -p ${ROS2_WS}/src/minimal_publisher
COPY ./ ${ROS2_WS}/src/minimal_publisher
# build repo
RUN cd ${ROS2_WS} \
&& colcon build \
&& source ${ROS2_WS}/install/setup.bash
CMD ["bash"]
However, this leads unfortunately to the strange error
CMake Error at CMakeLists.txt:13 (find_package): By not providing "Findament_cmake.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by
"ament_cmake", but CMake did not find one.
Could not find a package configuration file provided by "ament_cmake" with any of the following names:
ament_cmakeConfig.cmake
ament_cmake-config.cmake
Add the installation prefix of "ament_cmake" to CMAKE_PREFIX_PATH or set "ament_cmake_DIR" to a directory containing one of the above files. If "ament_cmake" provides a separate development package or SDK, be sure it has been installed.
If I remove the building process manually from the Dockerfile:
FROM ros:crystal
# install ros build tools
RUN apt-get update \
&& apt-get install -y python3-colcon-common-extensions \
&& rm -rf /var/lib/apt/lists/*
# clone ros package repo
ENV ROS2_WS /home/ros2_ws
RUN mkdir -p ${ROS2_WS}/src/minimal_publisher
COPY ./ ${ROS2_WS}/src/minimal_publisher
CMD ["bash"]
and run a docker container of the image, I can execute
cd ${ROS2_WS} \
&& colcon build \
&& source ${ROS2_WS}/install/setup.bash
without any error and the package builds perfectly?!
Do you have any idea what could be the issue?
Thanks!