Docker - ashBabu/Utilities GitHub Wiki
- This means building an image, say for arm64 device, from a x86 amd64 device
docker run --rm --privileged multiarch/qemu-user-static --reset -p yesdocker buildx create --usedocker buildx inspect --bootstrap
After the above, run the following on your x86 device
docker buildx build --platform linux/arm64 -t librealsense-arm .
docker tag [IMAGE_ID] [REPOSITORY]:[TAG]
-
If creating a Dockerfile, use
CMDto run the commands, for example, ros2 launch -
Then build the image or pull it from container registry and run
/usr/bin/docker run -dit --rm --privileged --device-cgroup-rule='c 81:* rmw' --device-cgroup-rule='c 189:* rmw' -v /dev/:/dev/ --ipc=host --pid=host --net=host --restart unless-stopped --name hai-slam-container -v /home/$USER/Downloads/saved_data:/root/saved_data/:rw ghcr.io/headlightai/slam-ros2-deploy:latest.
-
The
device-cgroup-rulesare specifically for realsense cameras. Without--privileged, realsense imu topics are not visible inside docker -
It will be running even after a system reboot
-
To stop it run
docker stop hai-slam-container
docker system df
-
docker builder prunehere
bash script to launch simulation using Nvidia graphics card:
-
xhost +local:* -
sudo docker run -it --rm -e DISPLAY=$DISPLAY \ --env="QT_X11_NO_MITSHM=1" \ --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \ --env="XAUTHORITY=$XAUTH" \ --volume="$XAUTH:$XAUTH" \ --runtime=nvidia \ --gpus all \ --privileged \ --net=host \ $USER/test_sim /bin/bash -c "terminator & terminator -e 'source /opt/ros/humble/setup.bash && source /ros2_ws/install/setup.bash && ros2 launch ardupilot_gz_bringup iris_maze.launch.py rviz:=false;/bin/bash ' & \ terminator -e 'source /opt/ros/humble/setup.bash && source /ros2_ws/install/setup.bash && ros2 launch ardupilot_ros cartographer.launch.py rviz:=false;/bin/bash' & \ terminator -e 'source /opt/ros/humble/setup.bash && source /ros2_ws/install/setup.bash && ros2 launch ardupilot_ros navigation.launch.py;/bin/bash' " -
xhost +local:* -
sudo docker run -it --rm -e DISPLAY=$DISPLAY \ --env="QT_X11_NO_MITSHM=1" \ --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \ --env="XAUTHORITY=$XAUTH" \ --volume="$XAUTH:$XAUTH" \ --privileged \ --net=host \ $USER/test_sim /bin/bash -c "terminator & terminator -e 'source /opt/ros/humble/setup.bash && source /ros2_ws/install/setup.bash && ros2 launch ardupilot_gz_bringup iris_maze.launch.py rviz:=false;/bin/bash ' & \ terminator -e 'source /opt/ros/humble/setup.bash && source /ros2_ws/install/setup.bash && ros2 launch ardupilot_ros cartographer.launch.py;/bin/bash' "
docker image tag old_name:latest new_name:latest
docker rm $(docker ps -a -f status=exited -q)
sudo sh -c 'docker rmi $(docker images -f "dangling=true" -q)'
Create a non-root user
# Create a non-root user
ARG USERNAME=ros
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& mkdir /home/$USERNAME/.config && chown $USER_UID:$USER_GID /home/$USERNAME/.config
Then run docker run -it --user Ash -v $PWD/folder_name:/home/folder_name my_image
#/bin/bash
set -e
source /opt/ros/humble/setup.bash
exec $@
Dockerfile~~~~~~
FROM ros:humble
RUN ...
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
CMD["bash"]
In the terminal, if you run, docker run -it container_name ros2 topic list, it replaces the bash in CMD and runs ros2 topic list
sudo service docker start
The following command will ensure that you can run docker with your user account (adding $USER to the docker group):
sudo usermod -a -G docker $USER
Note: Need to restart the system for the changes to take effect. Test it with docker run hello-world instead of sudo docker run hello-world
-
docker pull personalrobotics/ros-openrave -
docker ps -aand find thecontainer_nameunder IMAGE -
docker run -it --env="DISPLAY" --env="QT_X11_NO_MITSHM=1" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" container_nameto get a docker terminal -
To get access to a file in the computer inside docker "docker run -v 'pwd':'pwd' -w 'pwd' -i -t container_name pwd". More details here
-
The tutorial described here should ideally work with personalrobotics docker image but have not tested fully
The command rosrun moveit_kinematics auto_create_ikfast_moveit_plugin.sh --iktype Transform6D $MYROBOT_NAME.urdf <planning_group_name> <base_link> <eef_link> described here is erroring out with some sympy issues.
-
To pull latest ROS (as of now ROS2 Foxy) from here
sudo docker pull ros -
Docker is a headless machine. Hence to instruct docker to use the Host's display and run docker
sudo docker run -it --env="DISPLAY" --env="QT_X11_NO_MITSHM=1" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" ros -
The above will create a new user-like in terminal with
root<container_id>. However for GUI applications, might need to runxhost +local:rootfrom the HOST's terminal. more details. Usingxhost +local:rootis NOT recommended -
ros2 topic listwhich gives/parameter_events/rosout -
sudo apt-get update
If there is an error for the above command withGPG key error for Open Robotics, then runsudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 -
To install in the docker
sudo apt-get install ros-${ROS_DISTRO}-turtlesim -
ros2 run turtlesim turtlesim_node -
sudo docker exec -it <container_id> bashto get new terminal in docker -
In a new docker terminal,
ros2 run turtlesim turtle_teleop_key. Can use arrow keys to control the turtlebot -
sudo docker ps -ato list all docker containers -
The error libGL error: No matching fbConfigs or visuals found can be fixed with:
-
export LIBGL_ALWAYS_INDIRECT=1 -
The error libGL error: failed to load driver: swrast can be fixed with:
sudo apt-get install -y mesa-utils libgl1-mesa-glx -
Press
Ctrl + Dto exit a docker container -
To save changes to the docker container, first exit docker and in the HOST's terminal run
sudo docker commit container_id commit_name
might have to add sudo before running docker
docker versiondocker pull image_id-
docker psordocker ps -aordocker inspect container_name# To list containers docker stop container_namedocker rm container_name-
docker images# To see a list of downloaded images -
docker run container_name# To run latest -
docker run container_name:4# To run version 4 -
docker run -d container_name# To detach and run docker -
docker rmi image_name_or_id# To delete an image -
docker run -it image_name#i - interactiveandt - pseudo terminal docker run -p 80:5000 kodecloud/simple-webapp-
docker run -v /opt/datadir:/var/lib/mysql mysql# to store data to external location (/opt/datadir) from docker container -
docker run -e APP_COLOR=blue simple-webapp-color#estands forexport APP_COLOR=blue(or setting an environment variable) docker build -t nameOfFile .