Create Dockerfile
- See Nekton Docker
- Create
Dockerfile
# lightweight
FROM ros:humble-ros-core
# Install additional ROS 2 packages
RUN apt-get update && apt-get install -y \
ros-humble-demo-nodes-cpp
# Source the ROS install
RUN echo "source /opt/ros/humble/setup.bash >> ~/.bashrc"
# Set the default command (demo sample)
CMD ["bash", "-c", "source /opt/ros/humble/setup.bash && ros2 launch demo_nodes_cpp talker_listener.launch.py"]
- Build image
docker build -t ocr-docker:v1 .
- Check image creation
docker images
ocr-docker v1 cf75f4981718 13 months ago 423MB
- Run docker image
docker run ocr-docker:v1
[INFO] [launch]: All log files can be found below /root/.ros/log/2025-01-25-14-52-41-409104-07813b114052-1
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [talker-1]: process started with pid [51]
[INFO] [listener-2]: process started with pid [53]
[talker-1] [INFO] [1737816762.776286059] [talker]: Publishing: 'Hello World: 1'
[listener-2] [INFO] [1737816762.776651298] [listener]: I heard: [Hello World: 1]
[talker-1] [INFO] [1737816763.736002425] [talker]: Publishing: 'Hello World: 2'
[listener-2] [INFO] [1737816763.736310890] [listener]: I heard: [Hello World: 2]
[talker-1] [INFO] [1737816764.696676655] [talker]: Publishing: 'Hello World: 3'
[listener-2] [INFO] [1737816764.696984927] [listener]: I heard: [Hello World: 3]
[talker-1] [INFO] [1737816765.657298625] [talker]: Publishing: 'Hello World: 4'
[listener-2] [INFO] [1737816765.657616888] [listener]: I heard: [Hello World: 4]
Run container
https://foxglove.dev/blog/installing-ros2-on-macos-with-docker
- Run the container with interactive terminal
docker run -it ocr-docker:v1 bash
- Run the demo talker node
ros2 run demo_nodes_cpp talker
- Subscribe to the
/chatter
topipc
ros2 topic echo /chatter
data: 'Hello World: 7'
---
data: 'Hello World: 8'
---
data: 'Hello World: 9'
---
data: 'Hello World: 10'
---
data: 'Hello World: 11'
---
Visualize the data in Foxglove
- Update the Dockerfile
FROM ros:humble-ros-core
RUN apt-get update && apt-get install -y \
ros-humble-demo-nodes-cpp \
ros-humble-foxglove-bridge \
ros-humble-tf2-ros
- Launch the Foxglove ROS Bridge
docker run --rm -it -p 8765:8765 ocr-docker:v1 ros2 launch foxglove_bridge foxglov
e_bridge_launch.xml
- publish a transform
docker run --rm -it ocr-docker:v1 ros2 run tf2_ros static_transform_publisher --x 0 --y 1 --z 1 --roll 0 --pitch 0 --yaw 0 --frame-id base_link --child-frame-id sensor
0 --y 1 --z 1 --roll 0 --pitch 0 --yaw 0 --frame-id base_link --child-frame-id sensor
[INFO] [1737941432.540220875] [static_transform_publisher_dtFJIabvOYgEuQy8]: Spinning until stopped - publishing transform
translation: ('0.000000', '1.000000', '1.000000')
rotation: ('0.000000', '0.000000', '0.000000', '1.000000')
from 'base_link' to 'sensor'
- Use a direct URL to connect the Foxglove Desktop app to the WebSocket server running locally on port 8765
https://app.foxglove.dev/~/view?ds=foxglove-websocket&ds.url=ws%3A%2F%2Flocalhost%3A8765
Next
- See OCR Docker-v2