Skip to content

Commit 8eb7959

Browse files
authored
How to docker ubuntu (backport #291) (#379)
1 parent d5109a9 commit 8eb7959

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed

_scripts/start-docker.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
display_usage() {
4+
printf "Usage:\n start_docker <name_of_the_container> <name_of_the_image (optional)> <using_gpu (true) (optional)>\n"
5+
}
6+
7+
if [ -z "$1" ]
8+
then
9+
display_usage
10+
exit 1
11+
else
12+
CONTAINER_NAME=$1
13+
IMAGE_NAME=$2
14+
NO_GPU=$3
15+
if (docker ps --all | grep -q "$CONTAINER_NAME")
16+
then
17+
xhost +local:root &> /dev/null
18+
echo "Found a docker container with the given name, starting $1"
19+
printf "\n"
20+
# If Docker is already running, no need to start it
21+
if (docker ps | grep -q "$CONTAINER_NAME")
22+
then
23+
docker exec -it "$CONTAINER_NAME" /bin/bash && \
24+
xhost -local:root 1>/dev/null 2>&1
25+
else
26+
docker start "$CONTAINER_NAME" 1>/dev/null 2>&1
27+
docker exec -it "$CONTAINER_NAME" /bin/bash && \
28+
xhost -local:root 1>/dev/null 2>&1
29+
fi
30+
31+
else
32+
if [ -z "$2" ]
33+
then
34+
printf "Can't find docker with the given name, need an image name to start the container from\n"
35+
display_usage
36+
exit 1
37+
else
38+
echo "Creating docker container $1 from image $2"
39+
printf "\n"
40+
if [ -z "$3" ]
41+
then
42+
xhost +local:root &> /dev/null
43+
docker run -it --privileged \
44+
--net=host \
45+
--gpus all \
46+
--env=NVIDIA_VISIBLE_DEVICES=all \
47+
--env=NVIDIA_DRIVER_CAPABILITIES=all \
48+
--env=DISPLAY \
49+
--env=QT_X11_NO_MITSHM=1 \
50+
-v /tmp/.X11-unix:/tmp/.X11-unix \
51+
--name "$CONTAINER_NAME" \
52+
"$IMAGE_NAME" \
53+
/bin/bash
54+
xhost -local:root 1>/dev/null 2>&1
55+
else
56+
# Start without GPU
57+
echo "Opening up the docker container without GPU support"
58+
printf "\n"
59+
xhost +local:root &> /dev/null
60+
docker run -it --privileged \
61+
--net=host \
62+
--env=DISPLAY \
63+
--env=QT_X11_NO_MITSHM=1 \
64+
-v "/tmp/.X11-unix:/tmp/.X11-unix" \
65+
--name "$CONTAINER_NAME" \
66+
"$IMAGE_NAME" \
67+
/bin/bash
68+
xhost -local:root 1>/dev/null 2>&1
69+
fi
70+
fi
71+
fi
72+
fi

doc/how_to_guides/how_to_guides.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ These how-to guides will help you quickly solve specific problems using MoveIt.
88

99
how_to_guide
1010
how_to_generate_api_doxygen_locally
11+
how_to_setup_docker_containers_in_ubuntu
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
How to Set Up MoveIt 2 Docker Containers in Ubuntu
2+
===================================================
3+
This guide will provide a walkthrough on how to get a Docker container with MoveIt 2 dependencies set up quickly.
4+
It includes a script that will get you up and running in MoveIt quickly!
5+
This guide is intended for people who would like to have a separate environment for working with MoveIt up and running quickly \
6+
without having to do much configuring. In this guide, we will be setting up a ROS2 Humble environment.
7+
8+
Learning Objectives
9+
-------------------
10+
11+
- How to setup a Docker environment using the provided script
12+
13+
Requirements
14+
------------
15+
16+
- Ubuntu 20.04 or 22.04
17+
- `Docker Installation for Ubuntu <https://docs.docker.com/engine/install/ubuntu/>`_
18+
- `Nvidia drivers for Docker <https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#setting-up-nvidia-container-toolkit>`_
19+
20+
Steps
21+
-----
22+
1. Install Docker (a link is available in the Requirements section) and be sure to follow the `Linux Post Install <https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user>`_ instructions. If you do not complete these additional steps you will need to preface all ``docker`` commands with ``sudo``.
23+
24+
2. Open a terminal session, download the Docker script, and make it executable.
25+
26+
.. code-block:: bash
27+
28+
wget https://raw.githubusercontent.com/abake48/moveit2_tutorials/how-to-docker-ubuntu/_scripts/start-docker.sh -O ~/.local/bin/start-docker.sh
29+
chmod +x ~/.local/bin/start-docker.sh
30+
31+
3. Run the script.
32+
33+
There are 3 parameters for the script:
34+
- ``name_of_the_container`` : this is the name you wish to give the created container. For this guide, we will be naming the container ``moveit2-humble``.
35+
- ``name_of_the_image`` : if you are creating a fresh Docker container, provide the name of the Docker image here. For this guide, we will be using the image ``moveit/moveit2:humble-source``. Further explanation of this parameter is provided in the ``Further Reading`` section.
36+
- ``using_gpu`` : if ``true``, the Docker will be run using Nvidia GPU drivers. By default, this value is true.
37+
38+
To run the script and use Nvidia GPU drivers
39+
40+
.. code-block:: bash
41+
42+
start-docker.sh moveit2-humble moveit/moveit2:humble-source
43+
44+
If the above command fails, it is likely that Nvidia drivers cannot be used or are installed correctly. In which case, you can still proceed without using Nvidia drivers!
45+
First, you'll need to remove the container you just created by running the following command:
46+
47+
.. code-block:: bash
48+
49+
docker rm moveit2-humble
50+
51+
Then, to run the Docker container without the Nvidia drivers, run the following command:
52+
53+
.. code-block:: bash
54+
55+
start-docker.sh moveit2-humble moveit/moveit2:humble-source false
56+
57+
Running the script for the first time creates, starts, and executes the container ``moveit2-humble``.
58+
59+
4. You should now be inside of your Docker container, in the workspace directory. You should now be able to start working with MoveIt!
60+
61+
Whenever you wish to reenter your container, you can run the following command:
62+
63+
.. code-block:: bash
64+
65+
start-docker.sh moveit2-humble
66+
67+
Further Reading
68+
---------------
69+
- For more information about Docker best practices with respect to MoveIt,
70+
refer to `this blog post <https://picknik.ai/ros/robotics/docker/2021/07/20/Vatan-Aksoy-Tezer-Docker.html>`_
71+
from PickNik's Vatan Aksoy Tezer and Brennard Pierce.
72+
73+
- You can find a list of tagged images for the MoveIt 2 Docker container `here <https://hub.docker.com/r/moveit/moveit2/tags>`_.
74+
The tagged images coincide with ROS2 version releases. The ``release`` version of the container provides an environment in which MoveIt 2 is installed via the binaries.
75+
The ``source`` version of the Docker image will build MoveIt 2 from source.
76+
You can use any of the images in that link by substituting the second parameter in the script, ``name_of_the_image``, with moveit/moveit2:<tag_name>, where ``<tag_name>`` is from the above link.
77+
For example, this guide instructs you to use the image with the tag ``humble-source``.

0 commit comments

Comments
 (0)