This repository contains a Dockerized setup for running TurtleBot3 simulation with SLAM and Navigation capabilities using ROS Noetic on Windows. The setup includes Gazebo simulation, SLAM, and autonomous navigation capabilities.
tbot3-docker-windows.mp4
Docker is an open-source platform that automates the deployment, scaling, and management of applications by using containerization. Unlike traditional virtual machines, Docker containers share the host system's OS kernel, making them more lightweight and efficient.
Image credit: https://www.iteachrecruiters.com/blog/docker-explained-visually-for-non-technical-folks/
As illustrated in the image above, Docker provides several key advantages in a data center environment:
- Containerization: Docker packages applications and their dependencies into isolated containers, eliminating the "it works on my machine" problem
- Resource Efficiency: Containers share the OS kernel and use fewer resources than traditional VMs
- Isolation: Each container runs in isolation, preventing conflicts between applications
- Portability: Containers run consistently across different environments (development, testing, production)
Docker uses a client-server architecture with these main components:
- Docker Daemon: The background service running on the host that manages building, running, and distributing Docker containers
- Docker Client: The primary way to interact with Docker through the command line
- Docker Images: Read-only templates with instructions for creating containers
- Docker Containers: Runnable instances of Docker images
- Docker Registry: Repository for storing and sharing Docker images (like Docker Hub)
Here are some essential Docker commands:
# Display Docker version information
docker --version
# Download an image from Docker Hub
docker pull [image_name]:[tag]
# List all downloaded images
docker images
# Run a container from an image
docker run [options] [image_name]
# List running containers
docker ps
# List all containers (including stopped)
docker ps -a
# Stop a running container
docker stop [container_id]
# Remove a container
docker rm [container_id]
# Remove an image
docker rmi [image_id]
# Build an image from a Dockerfile
docker build -t [name]:[tag] [path_to_dockerfile]
# Execute a command in a running container
docker exec -it [container_id] [command]
# View container logs
docker logs [container_id]
# Create a network for container communication
docker network create [network_name]
Docker Compose is a tool for defining and running multi-container Docker applications. Key commands:
# Start services defined in docker-compose.yml
docker-compose up
# Run services in the background
docker-compose up -d
# Stop services
docker-compose down
# View service logs
docker-compose logs
- Install WSL2
- Install Docker Desktop for Windows
- Install Xming X Server - This is required for displaying GUI applications from Docker
- Clone this repository:
git clone https://github.com/prakash-aryan/turtlebot3-docker-windows.git
cd turtlebot3-docker-windows
- Pull the Docker image from Docker Hub:
docker pull merabro/turtlebot3-sim:latest
Open three PowerShell windows in the repository directory:
.\run_turtlebot.ps1
Once inside the container:
roslaunch turtlebot3_gazebo turtlebot3_world.launch
.\run_turtlebot.ps1
Once inside the container:
roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=gmapping
.\run_turtlebot.ps1
Once inside the container:
roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
-
Use teleop to drive the robot around and create the map:
- w: Move forward
- x: Move backward
- a: Turn left
- d: Turn right
- s: Stop
- Space: Emergency stop
- q: Quit
-
When satisfied with the map, in the teleop terminal:
# Stop teleop with Ctrl+C, then:
rosrun map_server map_saver -f /root/maps/my_map
After creating and saving a map, start navigation in a new terminal:
.\run_turtlebot.ps1
Once inside the container:
roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=/root/maps/my_map.yaml
Use the "2D Nav Goal" button in RViz to set navigation goals for the robot:
- Click on the "2D Nav Goal" button in the RViz toolbar
- Click and drag on the map to set the goal position and orientation
- The robot will plan a path and navigate to the goal
This TurtleBot3 Docker setup demonstrates several key advantages of containerization:
- Environment Consistency: All dependencies, ROS packages, and configurations are bundled together
- Cross-Platform Compatibility: Works seamlessly on Windows via WSL2
- Isolation: The ROS environment doesn't interfere with your host system
- Ease of Distribution: Anyone can run the same setup with a simple
docker pull
command - Resource Efficiency: Lighter than running a full virtual machine
- GUI Application Support: Runs graphical applications (Gazebo, RViz) through X11 forwarding
turtlebot3-docker-windows/
├── Dockerfile # Docker image configuration
├── start.sh # Container entrypoint script
├── run_turtlebot.ps1 # Windows PowerShell run script
├── maps/ # Directory for storing maps
└── README.md # This file
Our Dockerfile is built on top of a ROS Noetic base image and includes:
FROM osrf/ros:noetic-desktop-full
# Install dependencies
RUN apt-get update && apt-get install -y \
ros-noetic-turtlebot3 \
ros-noetic-turtlebot3-simulations \
ros-noetic-slam-gmapping \
ros-noetic-navigation \
&& rm -rf /var/lib/apt/lists/*
# Set environment variables
ENV TURTLEBOT3_MODEL=burger
ENV ROS_MASTER_URI=http://localhost:11311
ENV ROS_HOSTNAME=localhost
# Set up workspace
WORKDIR /root
# Copy entrypoint script
COPY start.sh /
RUN chmod +x /start.sh
# Create maps directory
RUN mkdir -p /root/maps
ENTRYPOINT ["/start.sh"]
- If Gazebo fails to launch or crashes:
- Verify Xming is running with the
-ac
flag - Restart Xming and try again
- Make sure your firewall isn't blocking Xming
- Verify Xming is running with the
- If ROS nodes can't communicate:
- Verify all containers are using the same network settings
- Check Docker Desktop network access
- Make sure all terminals are using the same ROS_MASTER_URI
- If you encounter "permission denied" errors:
- On Windows, ensure Docker Desktop has proper access to the shared folders
- On Linux, you might need to run Docker with sudo or add your user to the docker group
- If container exits immediately:
- Use
docker run
with the-it
flag to keep the container running - Check the logs with
docker logs [container_id]
to identify issues
- Use
- Gazebo is resource-intensive. For better performance:
- Allocate more CPU/RAM to Docker in Docker Desktop settings
- Close unnecessary applications while running the simulation
- Consider using a Linux host for better performance with Docker
- Docker Official Documentation
- Docker Hub - Public repository of Docker images
- Docker Curriculum - Comprehensive Docker tutorial
- Play with Docker - Interactive Docker playground