Create a project folder, and inside, create these scripts:
start-ros.sh: The purpose of this is to launch a ROS 2 container and bring up a terminal.
#!/bin/bash
docker run -ti --rm --name ros2 -v "$(pwd)/code/:/opt/code/" dnewmon/ros2:latest bash
ros.sh: The purpose of this script is to launch an additional ROS 2 terminal in the same Docker container.
#!/bin/bash
docker exec -ti --workdir "/opt/code/" ros2 bash
Within the $(pwd)/code/ path, create these additional scripts.
base-ros.sh: The purpose of this script is to source the base ROS 2 system (setup environment variables/paths/etc).
#!/bin/bash
source /opt/ros/${ROS_DISTRO}/setup.bash
ros.sh: The purpose of this script is to source the ROS 2 system + the current workspace (setup environment variables/paths/etc).
#!/bin/bash
source /opt/ros/${ROS_DISTRO}/setup.bash
source ./install/local_setup.bash
./start-ros.shsource base-ros.shros2 pkg create --build-type ament_cmake my_cbotcolcon buildsource ros.shros2 launch <project> <launch>In another terminal:
./ros.shsource ros.shros2 topic listOn the host machine, you and develop against the project files. Chances are you'll run into permissions issues with files created from within the Docker container. These two commands will allow access across the entire workspace for both container + host (or anybody else):
sudo chmod -R a+rxw .
sudo chown -R david:david .
Content type
Image
Digest
sha256:98d1a6a9c…
Size
889.5 MB
Last updated
over 3 years ago
docker pull dnewmon/ros2