Enter docker container5.1, related concepts5.2, How to query the docker image version used by the robot5.3. Edit scripts5.4, Execute the script5.5. multiple terminals enter the same docker container5.6, how to open a container that is already in the [Exited] closed state5.6.1, re-enter the container in the [Exited] closed state
The host is the server where we call commands to create containers using images. Here it refers to the main control Raspberry Pi on our car, and the host mentioned below refers to this.
xxxxxxxxxx
GUI is a graphical user interface, which mainly refers to: image window displayed by opencv, rviz interface, rqt interface, etc.
xxxxxxxxxx
The robot here is the raspbot v2 car, that is, the raspbot v2 car container with various development dependent environments configured
xxxxxxxxxx
docker images
Please select the name [yahboomtechnologyros-humble]. The version with the highest tag is the latest image version of the robot
If you have read the tutorial in [13, Docker ------ 3, docker image in-depth understanding and release image], you should know that docker image is a layered mechanism, that is, the image of the latter tag depends on the image of the previous tag. Therefore, there may be multiple versions of docker images in the host machine, and the tags of these images will be updated in an incremental manner.
Later, when we update new courses, we will also update functions by releasing new docker images.
Edit the script to run docker. This step is performed on the host machine:
xxxxxxxxxx
chmod +x docker_ros2.sh #Give the script executable permissions
The contents of the [docker_ros2.sh] script are as follows:
You can copy it directly without comments and modify it as needed
Note: When adding a host device to a container below, if the host machine is not connected to the device, you need to remove the corresponding addition operation to start the container
xxxxxxxxxx
#!/bin/bash
xhost +
docker run -it \
--privileged=true \
--net=host \
--env="DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
-v /tmp/.X11-unix:/tmp/.X11-unix \
--security-opt apparmor:unconfined \
-v /home/pi/temp:/root/temp \
-v /dev/i2c-1:/dev/i2c-1 \
-v /dev/i2c-0:/dev/i2c-0 \
--device=/dev/video0 \
--device=/dev/video1 \
--device=/dev/gpiomem \
yahboomtechnology/ros-humble:0.1.0 /bin/bash
Annotated script description:
Note: When adding a host device to a container, if the host is not connected to the device, you need to remove the corresponding addition operation to start the container.
x#!/bin/bash
xhost + # xhost is used to support the display of GUI in docker
docker run -it \ # interactively run docker image
--net=host \ # set the container network to host mode
--env="DISPLAY" \ # open the display GUI interface
--env="QT_X11_NO_MITSHM=1" \ # use X11 port 1 for display
-v /tmp/.X11-unix:/tmp/.X11-unix \ # map the display service node directory
--security-opt apparmor:unconfined \
-v /home/pi/temp:/root/temp \ # as a temporary file transfer directory between the host and the container, if you need to transfer files, you can use this directory
-v /dev/i2c-1:/dev/i2c-1 \ # add the host device to the container, i2c device port, if the car is not connected, please remove this line
-v /dev/i2c-0:/dev/i2c-0 \ #Add host device to container, i2c device port, if the car is not connected, please remove this line
--device=/dev/video0 \ #Add host device to container, camera device port, if the car is not connected to the camera, please remove this line
--device=/dev/video1 \ #Add host device to container, camera device port, if the car is not connected to the camera, please remove this line
--device=/dev/gpiomem \ #Add host device to container, Raspberry Pi gpio device port
yahboomtechnology/ros-humble:0.1.0 /bin/bash #The image name to be started, according to the modification found in step 5.2; execute the /bin/bash command in the container
#Note: When adding the host device to the container above, if the host is not connected to the device, you need to remove the corresponding addition operation to start the container
Note: This must be executed on the VNC of the car or on the car screen. It cannot be executed in the car terminal remotely entered through ssh (such as the car terminal entered through MobaXterm). Otherwise, the GUI image may not be displayed in the container. As shown below, after entering the car terminal in MobaXterm and executing run_docker.sh to enter the container, rviz cannot be displayed
Execute on the VNC interface of the car or on the car screen:
xxxxxxxxxx
./docker_ros2.sh
You can enter the container correctly and display the GUI screen. You can execute the rviz2 command again for testing.
If the GUI cannot be displayed after executing the rviz2 command, the following error is displayed: (usually it may appear in the Raspberry Pi master)
You need to add another parameter to the startup script:
xxxxxxxxxx
--security-opt apparmor:unconfined
That is:
xxxxxxxxxx
#!/bin/bash
xhost +
docker run -it \
--privileged=true \
--net=host \
--env="DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
-v /tmp/.X11-unix:/tmp/.X11-unix \
--security-opt apparmor:unconfined \ #Parameters for this sentence
-v /home/pi/temp:/root/temp \
-v /dev/i2c-1:/dev/i2c-1 \
-v /dev/i2c-0:/dev/i2c-0 \
--device=/dev/video0 \
--device=/dev/video1 \
--device=/dev/gpiomem \
yahboomtechnology/ros-humble:0.1.0 /bin/bash
Then run the script again to enter the container and display the GUI screen.
xxxxxxxxxx
docker ps
xxxxxxxxxx
docker exec -it da8c4f47020a /bin/bash
After successfully entering the container, you can open countless terminals to enter the container.
The robot project files are stored in the following directory:
xxxxxxxxxx
/root/yahboomcar_ws
Open the terminal on the docker host [i.e. the car, which can be executed on VNC or on the car screen]
Note: This must be executed on the car's VNC or on the car screen, and cannot be executed in the car terminal remotely entered through ssh (such as the car terminal entered through MobaXterm), otherwise the GUI image may not be displayed in the container. Of course, if you do not need to display the GUI image, then it is OK.
xxxxxxxxxx
docker ps -a
xxxxxxxxxx
xhost +
xxxxxxxxxx
docker start 5b
xxxxxxxxxx
docker exec -it 5b /bin/bash
xxxxxxxxxx
rviz2
xxxxxxxxxx
pi@yahboom:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5b698ea10535 yahboomtechnology/ros-foxy:3.3.9 "/bin/bash" 3 days ago Exited (0) 8 seconds ago ecstatic_lewin
pi@yahboom:~$ xhost +
access control disabled, clients can connect from any host
pi@yahboom:~$ docker start 5b
5b
pi@yahboom:~$ docker exec -it 5b /bin/bash
root@yahbooom:/# rviz2
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
[INFO] [1682298616.634096279] [rviz2]: Stereo is NOT SUPPORTED
[INFO] [1682298616.634576375] [rviz2]: OpenGl version: 3.1 (GLSL 1.4)
[INFO] [1682298617.959654036] [rviz2]: Stereo is NOT SUPPORTED