Skip to content

Commit 2c578b0

Browse files
committed
Update docker build script to build + run Zenoh + ROS in one container
1 parent 3627d44 commit 2c578b0

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed

content/learning-paths/cross-platform/zenoh-multinode-ros2/3_zenoh-multinode.md

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ weight: 4
66
layout: learningpathall
77
---
88

9-
## Deploying Zenoh on Multiple Raspberry Pi Devices Using Docker
9+
## Deploying Zenoh on Multiple Raspberry Pi Devices
1010

1111
After building Zenoh and its core examples, your next step is to deploy them across multiple Arm-based devices.
1212

13-
In this section, you’ll use Raspberry Pi boards to simulate a scalable, distributed environment, but the same workflow applies to any Arm Linux system, including Arm cloud instances.
13+
Once you’ve successfully installed Zenoh on an Arm Cortex-A or Neoverse platform in the previous session, you can either transfer the compiled binaries from `~/zenoh/target/release/` to your Raspberry Pi devices, or use Docker to quickly deploy them across multiple RPi nodes.
1414

15-
You’ll learn how to use Docker to deploy the environment on physical devices.
15+
In this session, you’ll use Raspberry Pi boards to simulate a scalable, distributed environment—but the same workflow applies to any Arm Linux system, including Arm cloud instances and Arm Virtual Hardware.
1616

1717
This setup lets you simulate real-world, cross-node communication, making it ideal for validating Zenoh's performance in robotics and industrial IoT use cases.
1818

19-
### Install Docker
20-
19+
### Install Docker on Raspberry Pi
2120
To simplify this process and ensure consistency, you can use Docker to containerize your Zenoh and ROS 2 environment.
2221
This lets you quickly replicate the same runtime on any device without needing to rebuild from source.
2322

@@ -30,16 +29,54 @@ curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh
3029
sudo usermod -aG docker $USER ; newgrp docker
3130
```
3231

33-
### Create a ROS 2 + DDS Docker Image
32+
### Create a ROS2 + Zenoh Docker Image
33+
34+
To ensure compatibility with ROS-related tools, create a `Dockerfile` based on `ros:galactic `, and use the official Rust installation method to build Zenoh, as shown below.
3435

35-
In a working directory, create a `Dockerfile` with the following content to create the ROS 2 / DDS docker image.
36+
This Dockerfile uses a multi-stage build process based on the ros:galactic environment.
37+
In the first stage, it installs Rust and compiles the Zenoh binaries directly from source.
38+
In the second stage, it installs essential ROS 2 demo tools and copies the Zenoh executables into the final runtime image.
3639

3740
```bash
38-
FROM ros:galactic
39-
RUN apt-get update
40-
RUN apt-get install -y ros-galactic-demo-nodes-cpp ros-galactic-rmw-cyclonedds-cpp ros-galactic-turtlesim
41+
# Stage 1: Build Zenoh using ROS base with Rust toolchain
42+
FROM ros:galactic AS builder
43+
44+
RUN apt-get update && apt-get install -y \
45+
curl \
46+
git \
47+
build-essential \
48+
pkg-config \
49+
clang \
50+
libssl-dev \
51+
cmake
52+
53+
RUN curl -sSf https://sh.rustup.rs -o rustup-init.sh && \
54+
chmod +x rustup-init.sh && \
55+
./rustup-init.sh -y --no-modify-path && \
56+
rm rustup-init.sh
57+
58+
ENV PATH="/root/.cargo/bin:${PATH}"
59+
60+
WORKDIR /root
61+
RUN git clone https://github.com/eclipse-zenoh/zenoh.git
62+
WORKDIR /root/zenoh
63+
RUN cargo build --release --all-targets -j $(nproc)
64+
65+
# Stage 2: Runtime with ROS + Zenoh binary only
66+
FROM ros:galactic AS runtime
67+
68+
RUN apt-get update && apt-get install -y \
69+
ros-galactic-demo-nodes-cpp \
70+
ros-galactic-rmw-cyclonedds-cpp \
71+
ros-galactic-turtlesim
72+
73+
COPY --from=builder /root/zenoh/target/release /root/zenoh/target/release
74+
4175
ENV RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
42-
CMD bash
76+
77+
WORKDIR /root/zenoh/target/release
78+
79+
CMD ["/bin/bash"]
4380
```
4481

4582
Under the directory where the above Dockerfile exists, run the following command to generate the docker image.
@@ -55,7 +92,8 @@ docker images | grep zenoh-node
5592
```
5693

5794
```output
58-
zenoh-node latest b7a9c27cf8a8 About a minute ago 962MB
95+
REPOSITORY TAG IMAGE ID CREATED SIZE
96+
zenoh-node latest 2300ea78d043 30 minutes ago 3.73GB
5997
```
6098

6199
### Transfer the Docker image to the other Raspberry Pi

0 commit comments

Comments
 (0)