#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 指令,包含以下功能 ✅:
✅ 功能清單
-
GUI 顯示支援(X11)
-
掛載 USB 裝置
/dev/ttyACM0
-
將本機當前目錄下的
./data/
資料夾,掛載至 container 的/home/ubuntu/data/
-
使用
--privileged
確保有完整裝置操作權限
🐳 最終指令如下:
📌 補充說明:
參數 | 功能說明 |
---|---|
xhost +local:ubuntu | 允許 container(以 ubuntu user 執行)使用 X11 |
--device=/dev/ttyACM0 | 掛載 USB Serial 裝置到 container 中 |
--volume="$(pwd)/data:/home/ubuntu/data" | 將本機目錄下的 ./data 映射到 container 內部 |
--privileged | 授權 container 操作 /dev 類裝置等 |
✅ 啟動後,你可以:
Docker 是支援 GPU 的,只要滿足以下條件,就可以在容器中使用 NVIDIA GPU 來加速 AI 推論、Gazebo 模擬、RViz 渲染等功能。
✅ 使用 GPU 的條件總覽
項目 | 說明 |
---|---|
GPU 驅動程式 (Driver) | 主機需先安裝 NVIDIA 官方驅動,非 nouveau |
NVIDIA Container Toolkit | 安裝 nvidia-docker2 或 nvidia-container-toolkit |
Docker 版本 | 建議 Docker CE 19.03 以上 |
NVIDIA GPU | 建議 CUDA Compute >= 5.0,例如 GTX 10xx / RTX / Jetson |
🧰 安裝流程:Docker 支援 GPU 的步驟
1️⃣ 安裝 NVIDIA Driver(在主機上)
請使用官方指令,或:
然後重開機:
2️⃣ 安裝 NVIDIA Container Toolkit
3️⃣ 測試 GPU 可用性
若成功,會看到熟悉的
nvidia-smi
顯示 GPU 資訊畫面 ✅
🚀 在 ROS2 Docker 中使用 GPU
✅ 範例 run 指令(支援 GPU + GUI + USB)
🎯 額外支援
應用 | Docker GPU 支援說明 |
---|---|
OpenCV + CUDA | 在容器中加裝 opencv-contrib-python 或自行 build with CUDA |
PyTorch / TensorRT | 使用 NVIDIA 官方容器即可支援 GPU 推論 |
Gazebo | RViz / Gazebo 使用 GPU 可提昇顯示效能 |
micro-ROS | 一般不使用 GPU,但可與視覺/SLAM 搭配 |
✅ 檢查容器內是否偵測到 GPU
或使用 ROS 範例查看 GPU 加速:
沒有留言:
張貼留言