#install docker
sudo apt install docker.io
#install ros2-humble
sudo docker pull osrf/ros:humble-simulation #you can pull complete humble version(simulate is simple)
#start ro2humble and mout directory
#[recommend,specify /tmp/.X11 and DISPLAY]
docker run -it --restart=always --name ros2humble -v /home/tom/Tom/DockerContent/nav2_ws(your docker path):/home/tom/Tom/DockerContent/nav2_ws(your local path) -v /tmp/.X11-unix:/tmp/.X11-unix:ro -e DISPLAY=$DISPLAY osrf/ros:humble-simulation /bin/bash
#look ro2humble container id
docker ps
#go into container ros2humble
docker exec -it containerID /bin/bash
#example:docker exec -it 726c5f11ac99 /bin/bash #ros+navigation
#download nav2-humble source(I download to **mypath**/nav2_ws/src)
https://github.com/ros-planning/navigation2/tree/humble
#git clone https://github.com/ros-planning/navigation2.git --branch humble
#init nav2_ws as ros directory method
source /opt/ros/humble/setup.bash
colcon build --symlink-install
#install dependcy(in nav2_ws directory)
apt-get update
rosdep install -i --from-path navigation2-humble --rosdistro humble -y
#compile nav2-humble(in nav2_ws directory)
colcon build #compile
##may exist problem(stderr:nav2_simple_commander)
pip install setuptools==58.2.0
colcon build #recompile
#OR
export ROS_DISTRO=rolling
docker build --tag navigation2:$ROS_DISTRO \
--build-arg FROM_IMAGE=ros:$ROS_DISTRO \
--build-arg OVERLAY_MIXINS="release ccache lld" \
--cache-from ghcr.io/ros-planning/navigation2:humble \
./navigation2
#open your local machine xhost for all user and client(for docker connect local graph resource)
sudo xhost +
#install rviz2/gazebo(humble-simulate not incluede them)
sudo apt update
sudo apt install ros-humble-rviz2
sudo apt install ros-humble-turtlebot3-gazebo
#test rviz2
method1:ros2 run rviz2 rviz2
method2:rviz2
#if you forgot (-e DISPLAY=$DISPLAY /tmp/.X11-unix:/tmp/.X11-unix:ro)
##stop docker first
systemctl stop docker
##modified config.v2.json hostconfig.json
sudo su
cd /var/lib/docker/containers
##go into the container which yours
###config.v2.json:
####mount qt-x11 path
"/tmp/.X11-unix": {
"Source": "/tmp/.X11-unix",
"Destination": "/tmp/.X11-unix",
"RW": false,
"Name": "",
"Driver": "",
"Type": "bind",
"Relabel": "ro", #this is:-v /tmp/.X11-unix:/tmp/.X11-unix:ro
"Propagation": "rprivate",
"Spec": {
"Type": "bind",
"Source": "/tmp/.X11-unix",
"Target": "/tmp/.X11-unix",
"ReadOnly": true
},
"SkipMountpointCreation": false
}
####modify env
"Env": [
"DISPLAY=:0",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"LANG=C.UTF-8",
"LC_ALL=C.UTF-8",
"ROS_DISTRO=humble"
],
####hostconfig.json
#mout qt-x11 path
"Binds": [
"/home/tom/Tom/DockerContent/nav2_ws:/home/tom/Tom/DockerContent/nav2_ws",
"/tmp/.X11-unix"
],
#format json
:%!python -m json.tool
#restart docker and container
systemctl start docker
docker start containerID
#run example
##setting
source /opt/ros/humble/setup.bash
source ./install/setup.bash #build from source code must use it,otherwise prompt couldn't find nav2_bringup
export TURTLEBOT3_MODEL=waffle
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:/opt/ros/humble/share/turtlebot3_gazebo/models
##run
ros2 launch nav2_bringup tb3_simulation_launch.py headless:=False
#other docker command
#look image:docker image ls
#start docker: sudo systemctl start docker
#stop docker: sudo systemctl stop docker
#start container:docker start containerID
#stop container:docker stop containerID