#add user ubuntu to images
# Dockerfile: ROS 2 Humble + MoveIt2 + Gazebo + micro-ROS Agent (source build)
FROM osrf/ros:humble-desktop-full
ENV DEBIAN_FRONTEND=noninteractive
# === 新增 ubuntu 使用者 ===
RUN useradd -m -s /bin/bash ubuntu && \
echo "ubuntu:ubuntu" | chpasswd && \
usermod -aG sudo ubuntu
# === 安裝基礎工具與依賴 ===
RUN apt update && apt install -y \
build-essential \
cmake \
git \
curl \
wget \
lsb-release \
gnupg2 \
python3-pip \
python3-colcon-common-extensions \
libboost-system-dev \
libtinyxml2-dev \
libyaml-cpp-dev \
nano tmux net-tools iputils-ping \
sudo \
ros-humble-rmw-fastrtps-cpp \
ros-humble-moveit \
ros-humble-moveit-setup-assistant \
ros-humble-gazebo-ros-pkgs \
ros-humble-ros2-control \
ros-humble-ros2-controllers && \
rm -rf /var/lib/apt/lists/*
# === 使用 ubuntu 用戶 ===
USER ubuntu
WORKDIR /home/ubuntu
ENV HOME=/home/ubuntu
# === 建立 micro-ROS Agent workspace ===
RUN mkdir -p /home/ubuntu/data/uros_ws/src
WORKDIR /home/ubuntu/data/uros_ws
# === Clone micro-ROS Agent + msgs ===
RUN git clone -b humble https://github.com/micro-ROS/micro-ROS-Agent.git src/micro_ros_agent && \
git clone -b humble https://github.com/micro-ROS/micro_ros_msgs.git src/micro_ros_msgs
# === Build Agent ===
RUN /bin/bash -c "source /opt/ros/humble/setup.bash && colcon build"
# === Source setup 環境 ===
RUN echo 'source /opt/ros/humble/setup.bash' >> /home/ubuntu/.bashrc && \
# echo 'source /home/ubuntu/data/uros_ws/install/setup.bash' >> /home/ubuntu/.bashrc
# === 建立 ROS2 工作目錄 ===
WORKDIR /home/ubuntu/ros2_ws
RUN mkdir -p /home/ubuntu/ros2_ws/src
CMD ["bash"]
=================================================
✅ 已根據你的需求更新 Dockerfile,具備以下特性:
-
🔐 新增用戶 ubuntu 並設定密碼為 ubuntu
-
📂 將 micro-ROS workspace 建置於 /home/ubuntu/data/uros_ws
-
🔁 自動載入 ROS 2 與 micro-ROS Agent 環境變數於 .bashrc
-
🔧 預設使用 ubuntu 使用者執行容器
🚀 建立與啟動容器
登入後執行:
以下是你需求的 完整 Docker run 指令,包含以下功能 ✅:
✅ 功能清單
🐳 最終指令如下:
📌 補充說明:
✅ 啟動後,你可以:
Docker 是支援 GPU 的,只要滿足以下條件,就可以在容器中使用 NVIDIA GPU 來加速 AI 推論、Gazebo 模擬、RViz 渲染等功能。
✅ 使用 GPU 的條件總覽
🧰 安裝流程:Docker 支援 GPU 的步驟
1️⃣ 安裝 NVIDIA Driver(在主機上)
請使用官方指令,或:
然後重開機:
2️⃣ 安裝 NVIDIA Container Toolkit
3️⃣ 測試 GPU 可用性
若成功,會看到熟悉的 nvidia-smi 顯示 GPU 資訊畫面 ✅
🚀 在 ROS2 Docker 中使用 GPU
✅ 範例 run 指令(支援 GPU + GUI + USB)
🎯 額外支援
✅ 檢查容器內是否偵測到 GPU
或使用 ROS 範例查看 GPU 加速: