Background Story: Why Is Everyone Talking About “Containerization”? #
Imagine needing your robot service to run reliably on different computers and environments. Traditional installation steps are tedious, and environment configuration is prone to errors. That’s when Docker containers come in—they’re like putting your service into a “suitcase,” ready to be “unpacked” and started instantly wherever you go!
In smart manufacturing, logistics, healthcare, and other fields, ROS (Robot Operating System) is already the leading platform for robotics development, and ROS2 brings even more possibilities for distributed, multi-device collaboration. Containerization perfectly solves the “deployment challenge” for ROS2 services—standardizing development, testing, and production.
Advantech Technology Lab: How to Build Your ROS2 Container in 5 Steps #
In this experiment, we use Advantech’s self-developed ROS2 base image (advigw/dev-ros2-<ROS_DISTRO>:1.0.0) to demonstrate how to quickly package a ROS2 application service with Docker. Here are the practical steps we followed:
Step 1: Create a Custom Dockerfile #
First, create a file named Dockerfile. This file serves as your “recipe,” determining which ingredients (dependencies) your ROS2 service container will have, how to “cook” them (installation commands), and how to ensure it starts up automatically, ready to use.
FROM advigw/dev-ros2-<ROS_DISTRO>:1.0.0
# 1. Copy necessary application files into the container
# WORKDIR /root
# COPY prerequisite/<your_application> /root/prerequisite
# 2. Install related packages or dependencies
# RUN apt-get update
# RUN apt-get install <some_dependency>
# 3. Set the application to automatically execute when the container starts
# CMD [<application_command>]
Step 2: Build the Image with Docker CLI #
Open your terminal and enter the following command in your project directory:
docker build -t ros-example -f Dockerfile .
This will create a container image named ros-example, which you can then easily replicate and deploy!
Step 3: Write docker-compose.yml to Orchestrate Multiple Services #
Want to manage multiple services at once? Use a docker-compose.yml file! This configuration file lets you define how all containers should start, how they connect to each other, and easily adjust environment variables.
version: '2.1'
services:
ros-example:
image: ros-example
container_name: ros-example
restart: always
networks:
- adv-ros-network
logging:
options:
max-size: 10M
environment:
- ROS_DOMAIN_ID=${ROS_DOMAIN_ID}
networks:
adv-ros-network:
name: adv-ros-network
Step 4: Start All Containers with One Command #
Once everything is set up, run the following command in the folder containing your docker-compose.yml file:
docker-compose -f docker-compose.yml up -d
Tip: It is recommended not to use
sudowhen running this step, otherwise the critical environment variableROS_DOMAIN_IDmay not work properly!
Step 5: Access the Container for Real-Time Verification #
Finally, open an interactive shell to directly enter the ROS2 service container for testing:
docker exec -it ros-example bash
This allows you to check the application status anytime or proceed with further development!
Experiment Highlights and Application Value #
- Rapid Deployment, Time-Saving and Efficient: Developers and customers only need a few commands to deploy ROS2 services on any computer equipped with Docker.
- Consistent Environments, Fewer Errors: No more “it works on my machine but not on yours” issues—containers ensure your software environment is fully packaged!
- Flexible Scalability, Unlimited Future: Use Compose to manage multiple ROS2 services, making it super easy to integrate AI, IoT, or other advanced applications in the future.
- Advantech’s Ongoing Innovation: This workflow is built on our self-developed ROS2 images and tailored to industry needs, showcasing our strong capabilities in robotics and automation.
Conclusion and Future Outlook #
This experiment proves that with container technology, deploying and managing ROS2 can be remarkably simple! Advantech not only provides a stable and reliable development foundation but also continues to innovate smarter and more flexible technical solutions, helping customers quickly implement AIoT, smart robotics, and other innovative applications.
In the future, we will continue to optimize the containerization process, introduce more automation, remote maintenance, and enhanced security features, and work hand-in-hand with partners to create a new era of intelligent industries! Want to know more technical details or application cases? Stay tuned to the Advantech blog and join us in exploring the future of technology!