# ============================================================================= # RDC Simulation - Docker Build (GPU-enabled) # ============================================================================= # Builds a complete ArduPilot + Gazebo simulation environment with GPU support. # Your host system bashrc is NOT modified - everything stays in the container. # # Build: # docker build -t rdc-simulation . # # Run (with GPU): # docker run --gpus all -it --rm \ # -e DISPLAY=$DISPLAY \ # -v /tmp/.X11-unix:/tmp/.X11-unix \ # rdc-simulation # # Or use docker-compose: # docker compose up # ============================================================================= FROM ubuntu:24.04 # Avoid interactive prompts during build ENV DEBIAN_FRONTEND=noninteractive ENV TZ=UTC # ============================================================================= # SYSTEM DEPENDENCIES # ============================================================================= RUN apt-get update && apt-get install -y \ # Build tools curl \ wget \ git \ cmake \ build-essential \ gnupg \ lsb-release \ software-properties-common \ # Python python3 \ python3-pip \ python3-venv \ python3-dev \ # Graphics / X11 libgl1-mesa-glx \ libgl1-mesa-dri \ mesa-utils \ x11-apps \ # Video recording ffmpeg \ xdotool \ wmctrl \ # Networking netcat-openbsd \ # GStreamer (for ArduPilot Gazebo plugin) libgstreamer1.0-dev \ libgstreamer-plugins-base1.0-dev \ gstreamer1.0-plugins-bad \ gstreamer1.0-libav \ gstreamer1.0-gl \ # OpenCV libopencv-dev \ && rm -rf /var/lib/apt/lists/* # ============================================================================= # ROS 2 JAZZY # ============================================================================= RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg \ && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu noble main" > /etc/apt/sources.list.d/ros2.list \ && apt-get update \ && apt-get install -y \ ros-jazzy-ros-base \ ros-jazzy-geometry-msgs \ ros-jazzy-std-msgs \ ros-jazzy-nav-msgs \ ros-jazzy-sensor-msgs \ ros-jazzy-ros-gz \ && rm -rf /var/lib/apt/lists/* # ============================================================================= # GAZEBO HARMONIC # ============================================================================= RUN wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg \ && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable noble main" > /etc/apt/sources.list.d/gazebo-stable.list \ && apt-get update \ && apt-get install -y gz-harmonic \ && rm -rf /var/lib/apt/lists/* # ============================================================================= # CREATE NON-ROOT USER # ============================================================================= ARG USERNAME=pilot ARG USER_UID=1000 ARG USER_GID=1000 RUN groupadd --gid $USER_GID $USERNAME \ && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ && apt-get update \ && apt-get install -y sudo \ && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ && chmod 0440 /etc/sudoers.d/$USERNAME \ && rm -rf /var/lib/apt/lists/* USER $USERNAME WORKDIR /home/$USERNAME # ============================================================================= # ARDUPILOT SITL # ============================================================================= RUN git clone --recurse-submodules https://github.com/ArduPilot/ardupilot.git /home/$USERNAME/ardupilot # Install ArduPilot prerequisites (writes to container's bashrc, not host) WORKDIR /home/$USERNAME/ardupilot RUN Tools/environment_install/install-prereqs-ubuntu.sh -y # Build ArduCopter SITL RUN . ~/.profile && ./waf configure --board sitl && ./waf copter # ============================================================================= # ARDUPILOT GAZEBO PLUGIN # ============================================================================= RUN git clone https://github.com/ArduPilot/ardupilot_gazebo.git /home/$USERNAME/ardupilot_gazebo WORKDIR /home/$USERNAME/ardupilot_gazebo RUN mkdir -p build && cd build \ && cmake .. -DCMAKE_BUILD_TYPE=Release \ && make -j$(nproc) # ============================================================================= # PYTHON DEPENDENCIES (MAVProxy, pymavlink) # ============================================================================= RUN pip3 install --user --break-system-packages pymavlink mavproxy pexpect pybullet numpy pillow opencv-python # ============================================================================= # COPY PROJECT FILES # ============================================================================= WORKDIR /home/$USERNAME/RDC_Simulation COPY --chown=$USERNAME:$USERNAME . . # Create venv and install requirements RUN python3 -m venv venv \ && . venv/bin/activate \ && pip install --upgrade pip \ && pip install -r requirements.txt # ============================================================================= # ENVIRONMENT SETUP (container only - doesn't touch host) # ============================================================================= ENV ARDUPILOT_HOME=/home/pilot/ardupilot ENV PATH="${PATH}:/home/pilot/ardupilot/Tools/autotest:/home/pilot/.local/bin" ENV GZ_SIM_SYSTEM_PLUGIN_PATH=/home/pilot/ardupilot_gazebo/build ENV GZ_SIM_RESOURCE_PATH=/home/pilot/ardupilot_gazebo/models:/home/pilot/ardupilot_gazebo/worlds:/home/pilot/RDC_Simulation/gazebo/models # Source ROS2 and ArduPilot env in bashrc (container's bashrc, not host) RUN echo 'source /opt/ros/jazzy/setup.bash' >> ~/.bashrc \ && echo 'source ~/.ardupilot_env 2>/dev/null || true' >> ~/.bashrc \ && echo 'source ~/RDC_Simulation/venv/bin/activate' >> ~/.bashrc \ && echo 'export ARDUPILOT_HOME=~/ardupilot' >> ~/.bashrc \ && echo 'export PATH=$PATH:~/ardupilot/Tools/autotest:~/.local/bin' >> ~/.bashrc \ && echo 'export GZ_SIM_SYSTEM_PLUGIN_PATH=~/ardupilot_gazebo/build' >> ~/.bashrc \ && echo 'export GZ_SIM_RESOURCE_PATH=~/ardupilot_gazebo/models:~/ardupilot_gazebo/worlds:~/RDC_Simulation/gazebo/models' >> ~/.bashrc # ============================================================================= # ENTRYPOINT # ============================================================================= COPY --chown=$USERNAME:$USERNAME docker-entrypoint.sh /home/$USERNAME/docker-entrypoint.sh RUN chmod +x /home/$USERNAME/docker-entrypoint.sh WORKDIR /home/$USERNAME/RDC_Simulation ENTRYPOINT ["/home/pilot/docker-entrypoint.sh"] CMD ["bash"]