This project provides a Dockerized environment for running the husarion_ugv_ros stack for ROS 2 Jazzy, primarily for simulation purposes. It includes a setup script to build the Docker image and configure convenient aliases for launching the container with different GPU configurations.
Before you begin, ensure you have the following installed on your host Linux system:
- Docker Engine: Follow the official Docker installation guide for your Linux distribution.
- Git: For cloning repositories if needed.
- (For NVIDIA GPU Users)
- NVIDIA Drivers for Linux.
- NVIDIA Container Toolkit (
nvidia-docker2).
- (For AMD GPU Users)
- Up-to-date Mesa drivers for your AMD GPU/APU.
- X11 Server: Standard on most Linux desktop environments.
Dockerfile: Defines the Docker image, installing ROS 2 Jazzy,husarion_ugv_ros, and its dependencies.entrypoint.sh: Script executed when the Docker container starts. It sources the ROS 2 and workspace environments.setup_docker.sh: A shell script to automate building the Docker image and adding run aliases to your.bashrc.
-
Clone/Download Files: Ensure
Dockerfile,entrypoint.sh, andsetup_docker.share in the same directory. -
Make
setup_docker.shExecutable: Open a terminal in the directory containing the files and run:chmod +x setup.sh
-
Run the Setup Script: Execute the script:
./setup.sh
This script will:
- Build the Docker image (default name:
my-husarion-app:jazzy). You can change this in the script. - Add/Update aliases to your
$HOME/.bashrcfile for running the container with different GPU options.
- Build the Docker image (default name:
-
Source
.bashrc: For the new aliases to take effect in your current terminal session, source your.bashrcfile or open a new terminal:source ~/.bashrc
The
xhost +local:dockercommand (to allow GUI applications from Docker to display) will now be executed automatically each time you use one of therun_husarion_*aliases.
After setup, you can use the following aliases to run the container. Each alias will automatically attempt to authorize Docker to access your X display by running xhost +local:docker before starting the container.
-
No Dedicated GPU Acceleration:
run_husarion_nogpu
-
NVIDIA GPU Acceleration:
run_husarion_nvidia
-
AMD GPU Acceleration:
run_husarion_amd
(The actual commands executed by these aliases now include
xhost +local:docker &&at the beginning.)
Once the container is running, you'll be at a bash prompt inside the Docker environment. The ROS 2 Jazzy environment and your Husarion workspace (/husarion_ws or /ros2_ws as per your Dockerfile) will be sourced.
You can now run ROS 2 commands:
-
Launch Gazebo Simulation:
ros2 launch husarion_ugv_gazebo core_gazebo.launch.py
(Or other Gazebo launch files from
husarion_ugv_gazebo) -
Launch Rviz2: In a new terminal, first attach to the same running container: If you named your container (e.g.,
husarion_amd):docker exec -it husarion_amd bashThen, inside this new container terminal:
ros2 launch husarion_ugv_viz view_robot.launch.py
Docker is excellent for ensuring consistent development and runtime environments across a team. Here's how to leverage this setup collaboratively:
-
Version Control for Docker Setup:
- Commit all setup files: The
Dockerfile,entrypoint.sh, andsetup_docker.shshould be committed to a Git repository (e.g., your main project repository). - This allows every team member to clone the repository and have the exact same instructions for building the Docker image.
- Commit all setup files: The
-
Building the Image Locally (Recommended for Development):
- Each team member clones the repository.
- Each team member runs the
./setup_docker.shscript on their own machine.- This ensures the image is built using the latest committed
Dockerfile. - It also sets up the convenient run aliases locally for them.
- This ensures the image is built using the latest committed
- Consistency: As long as everyone builds from the same committed
Dockerfile, their environments will be consistent.
-
Sharing Pre-built Images (Optional, for CI/CD or specific deployments):
- You can push the built Docker image to a container registry like Docker Hub, GitHub Container Registry (GHCR), GitLab Container Registry, or a private registry.
- Tagging: Use meaningful tags for your images (e.g.,
yourteam/my-husarion-app:jazzy-v1.0,yourteam/my-husarion-app:jazzy-latest). - Pulling: Team members can then pull the pre-built image instead of building it locally:
docker pull yourregistry/yourimage:tag
- Updating Aliases: If using pre-built images, the
IMAGE_NAMEinsetup_docker.sh(or directly in.bashrcaliases) would need to point to the registry image (e.g.,yourregistry/yourimage:tag). The build step insetup_docker.shcould be skipped or made conditional. - Pros: Saves build time for each user, ensures bit-for-bit identical images.
- Cons: Requires registry setup and management;
Dockerfilechanges need a new image to be built and pushed.
-
Host Environment Still Matters (GPU, X11):
- While the Docker container provides a consistent software environment, team members will still need to correctly configure their host machines for Docker, especially for GUI and GPU access.
- This includes:
- Installing Docker.
- Installing appropriate GPU drivers (NVIDIA/AMD).
- Installing the NVIDIA Container Toolkit (for NVIDIA users).
- Using
xhost +local:dockeror a similar mechanism for X11 forwarding (the aliases help automate this part).
- The provided run aliases (
run_husarion_nvidia,run_husarion_amd) help abstract some of these host-specific Docker run commands, but the underlying host setup must be correct.
-
Communication and Updates:
- When the
Dockerfileis updated (e.g., new dependencies added), communicate this to the team. - Team members will need to:
- Pull the latest changes from Git.
- Re-run
./setup_docker.shto rebuild the image with the newDockerfileand update aliases. - Or, if using a registry, pull the newly pushed image version.
- When the
By following these practices, your team can significantly benefit from the consistency and portability offered by Docker, leading to fewer "it works on my machine" issues.
- General: The
xhost +local:dockercommand is now part of the aliases. If GUIs still don't appear, ensure your X server is running andDISPLAYenvironment variable is correctly set on the host. - NVIDIA:
- Verify
nvidia-smiworks on the host. - Ensure NVIDIA Container Toolkit is correctly installed.
- Check Docker daemon logs (
sudo journalctl -u docker.service) for errors related to the NVIDIA runtime.
- Verify
- AMD:
- Verify
glxinfo -Bon the host shows your AMD GPU and direct rendering. - Ensure your user on the host is part of the
videoand/orrendergroup (sudo usermod -aG video $USER && sudo usermod -aG render $USER, then log out/in). - Check permissions of
/dev/dri/*devices. - Inside the container, run
glxinfo -B. It should show your AMD GPU, notllvmpipe.
- Verify
- Image Name & Resource Limits: You can change the
IMAGE_NAME,CPU_LIMIT, andMEMORY_LIMITvariables at the top ofsetup_docker.shbefore running it. - Aliases: After running the setup script, you can manually edit the aliases in your
~/.bashrcfile if you need further customization.