How to run a ROS2 node inside docker image?
Question:
I have a ros2 package and successfully create a docker image of it. Then when im inside the container i would like to run only one single node of the ros2 package. So first create the environment with PATH=$PATH:/home/user/.local/bin
then vcs import . <system_integration/ros.repos
then docker pull ghcr.io/test-inc/base_images:foxy
. Im running and executing the docker with
docker run --name test -d --rm -v $(pwd):/home/ros2/foxy/src ghcr.io/company-inc/robot1_vnc_ros2:foxy
docker exec -it test /bin/bash
Then when Im inside the docker I build the package with
colcon build –symlink-install –event-handlers console_cohesion+ –cmake-args -DCMAKE_BUILD_TYPE=Release –packages-up-to system_integration
So now im inside the docker in the root@1942eef8d977:~/ros2/foxy
and would like to run one python node. But ros2 run package_name node_name
would not work right? Im not familiar much with docker so not sure how to run the node. Any help
Thanks
Answers:
Have you sourced the setup file within the container?
Where ever the package source is located, you need to run source ./install/setup.bash
Before you can use ros2 run to run packages, you have to source the correct workspace. Otherwise you could not use auto-completion tab
to find any packages and thus no package can be run
To do so:
cd
into your the root path of your workspace
colcon build
your workspace (which your packages should under the src
directory)
- run this line to source it
source install/setup.bash
- you can check it with
echo $COLCON_PATH_PREFIX
to see the path is correctly sourced
- Try rerun the ros2 command to start your node
I have a ros2 package and successfully create a docker image of it. Then when im inside the container i would like to run only one single node of the ros2 package. So first create the environment with PATH=$PATH:/home/user/.local/bin
then vcs import . <system_integration/ros.repos
then docker pull ghcr.io/test-inc/base_images:foxy
. Im running and executing the docker with
docker run --name test -d --rm -v $(pwd):/home/ros2/foxy/src ghcr.io/company-inc/robot1_vnc_ros2:foxy
docker exec -it test /bin/bash
Then when Im inside the docker I build the package with
colcon build –symlink-install –event-handlers console_cohesion+ –cmake-args -DCMAKE_BUILD_TYPE=Release –packages-up-to system_integration
So now im inside the docker in the root@1942eef8d977:~/ros2/foxy
and would like to run one python node. But ros2 run package_name node_name
would not work right? Im not familiar much with docker so not sure how to run the node. Any help
Thanks
Have you sourced the setup file within the container?
Where ever the package source is located, you need to run source ./install/setup.bash
Before you can use ros2 run to run packages, you have to source the correct workspace. Otherwise you could not use auto-completion tab
to find any packages and thus no package can be run
To do so:
cd
into your the root path of your workspacecolcon build
your workspace (which your packages should under thesrc
directory)- run this line to source it
source install/setup.bash
- you can check it with
echo $COLCON_PATH_PREFIX
to see the path is correctly sourced - Try rerun the ros2 command to start your node