This repository contains a Docker-based development environment for ROS2 Humble, specifically configured for macOS with Apple Silicon (M1/M2) processors.
- Download Docker Desktop from https://www.docker.com/products/docker-desktop
- Install Docker Desktop
- Start Docker Desktop and wait for it to be running (you'll see the whale icon in your menu bar)
- ARM64 (aarch64): Used by Apple Silicon (M1/M2) Macs
- AMD64 (x86_64): Used by Intel/AMD processors and Intel-based Macs
To check your Mac's architecture:
uname -m- If it shows
arm64, you have an Apple Silicon Mac - If it shows
x86_64, you have an Intel-based Mac
This matters because:
- ROS2 packages need to match your system architecture
- Running AMD64 containers on ARM64 requires emulation (slower)
- Our Dockerfile is configured for ARM64 to ensure native performance
ros2_docker_dev/
├── Dockerfile # Container configuration
├── docker-compose.yml # Container orchestration
├── .dockerignore # Files to exclude from build
└── workspace/ # Your ROS2 workspace
└── src/ # Source code directory
- Clone this repository:
git clone <repository-url>
cd ros2_docker_dev- Build the Docker image:
docker-compose build- Start the container:
docker-compose up -d- Enter the container:
docker exec -it ros2_docker bashInside the container, you can test ROS2 with the demo nodes:
- Open two terminal windows
- In the first terminal (talker):
ros2 run demo_nodes_py talker- In the second terminal (listener):
ros2 run demo_nodes_py listenerYou should see messages being published and received between the nodes.
Docker containers are isolated environments that don't have direct access to your system's display. To run GUI applications (like RViz2) from within a container, we use a web-based VNC solution (noVNC) that provides a virtual display and allows you to access it through your web browser.
This approach:
- Works reliably on all platforms, including Apple Silicon Macs
- Doesn't require XQuartz or other X11 forwarding setup
- Provides a secure, web-based interface to the container's display
-
Rebuild the container with GUI support:
docker-compose down docker-compose build docker-compose up -d
-
Access the web interface:
- Open http://localhost:6080/vnc.html in your web browser
- Enter the VNC password (default is "password" unless you set VNC_PASSWORD)
- Click "Connect"
-
Test the setup:
docker exec -it ros2_docker bash rviz2
- The virtual display uses software rendering, which can be CPU-intensive
- Default resolution is 1024x768 to balance performance and usability
- If you experience high CPU usage:
- Close RViz2 when not in use
- Use a lower resolution by modifying the Xvfb command in start.sh
- Consider using headless mode for non-interactive tasks
You can customize the VNC password by setting the VNC_PASSWORD environment variable:
echo "VNC_PASSWORD=your_secure_password" > .env
docker-compose up -d-
Docker Desktop not running
- Ensure Docker Desktop is running (whale icon in menu bar)
- Try restarting Docker Desktop
-
Permission issues
- Docker Desktop needs full disk access on macOS
- Check System Preferences → Security & Privacy → Privacy → Full Disk Access
-
Network issues
- Ensure Docker Desktop has network access
- Check Docker Desktop settings → Resources → Network
-
GUI issues
- If noVNC page doesn't load:
- Check if container is running:
docker ps - Verify port 6080 is accessible:
curl localhost:6080 - Check container logs:
docker logs ros2_docker
- Check if container is running:
- If VNC connection fails:
- Verify VNC password is correct
- Check if port 5901 is accessible
- Try refreshing the browser page
- If RViz2 is slow or unresponsive:
- Reduce display resolution in start.sh
- Close other resource-intensive applications
- Consider using headless mode for non-interactive tasks
- If noVNC page doesn't load:
- Your local
workspacedirectory is mounted to/root/ros2_wsin the container - Create new ROS2 packages in
workspace/src - Build packages using
colcon buildinside the container - Source your workspace:
source /root/ros2_ws/install/setup.bash
- Exit the container:
exit- Stop the container:
docker-compose down