Introduction
In a fast-paced development environment, having a simulation that runs out of the box is crucial. While it might seem challenging, setting up a Gazebo simulation environment using Docker Compose is straightforward. This guide will walk you through the necessary steps.
Prerequisites
- Docker and Docker Compose installed on your machine.
- Basic understanding of Docker and command-line operations.
The Plan
We’ll use Docker Compose to run an Ubuntu-based Docker image with access to your system’s hardware, including the network and GPU. This tutorial is intended for development purposes only.
Steps to Setup and Run Gazebo
Clone the Repository
First, clone the project repository from GitHub:
git clone https://github.com/offgrid88/ros2-on-intel.git
Change into the project directory:
cd ros2-on-intel
Get the Right Group Number
To ensure the Docker container has the correct permissions, find the group number for the render
group:
getent group render | cut -d: -f3
Update Docker Compose Configuration
Open the docker-compose_dev.yml file in your preferred text editor. Locate the group_add
section and update the group number with the value obtained from the previous command. It should look something like this:
group_add: - "your_group_number"
Save and close the file.
Build and Run the Docker Container
Now, build and run the Docker container using Docker Compose:
docker compose -f docker-compose_dev.yml build docker compose -f docker-compose_dev.yml up -d
Access the Running Container
To interact with the ROS2 environment inside the container, execute the following command:
docker exec -it ros2-on-intel-ros2_dev-1 bash
Run Gazebo
Once inside the container, start Gazebo:
gazebo
You should see Gazebo up and running, allowing you to interact with the simulation environment.
Manage Permissions
If you encounter any permission issues, adjust the ownership of the build, log, and install directories:
sudo chown -R $USER:$USER build sudo chown -R $USER:$USER log sudo chown -R $USER:$USER install
Re-accessing the ROS Environment
Whenever you need to access the ROS2 environment again, use the following command:
docker exec -it ros2-on-intel-ros2_dev-1 bash
Conclusion
By following these steps, you should have a fully functional Gazebo simulation environment running inside a Docker container, ready for your development needs. This setup ensures a consistent and isolated environment, making development and testing more efficient.
Feel free to explore and customize the environment further to suit your specific requirements. Happy coding!