Skip to content

Commit

Permalink
Mount Xauthority into Docker containers (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
EzraBrooks committed Sep 4, 2024
1 parent 0c482ba commit a8b90ca
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 8 deletions.
21 changes: 19 additions & 2 deletions moveit2/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,22 @@ IMG_NAME=openrobotics/moveit2
CONTAINER_NAME="$(tr '/' '_' <<< "$IMG_NAME")"

# Start the container
docker run --rm -it --name $CONTAINER_NAME --network host \
-e DISPLAY -e TERM -e QT_X11_NO_MITSHM=1 $IMG_NAME
# --rm: delete container after exiting
# -it: Interactive TTY mode so you can use a shell.
# --network host: Does not isolate Docker container from host's network interfaces.
# Allows all traffic to pass through as if it originated from the host.
# In our case, useful for DDS traffic for ROS.
# -e DISPLAY: Pass the X11 display through to the container.
# -e TERM: Pass the kind of terminal being used through to the container.
# -e QT_X11_NO_MITSHM=1: Disables shared memory extension for Qt/X11, which does not work consistently inside a process namespace like a container.
# -v "$XAUTHORITY:/.Xauthority": the $XAUTHORITY environment variable on the host contains the path to a file that grants access to X11.
# We mount the path defined in that environment variable into the container at /.Xauthority.
# -e XAUTHORITY=/.Xauthority: We set $XAUTHORITY *inside* the container to the place we just mounted the Xauthority (/.Xauthority)
docker run --rm -it --name $CONTAINER_NAME \
--network host \
-e DISPLAY \
-e TERM \
-e QT_X11_NO_MITSHM=1 \
-v "$XAUTHORITY:/.Xauthority" \
-e XAUTHORITY=/.Xauthority \
$IMG_NAME
21 changes: 19 additions & 2 deletions nav2_demo/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,22 @@ IMG_NAME=osrf/space_nav2_demo
CONTAINER_NAME="$(tr '/' '_' <<< "$IMG_NAME")"

# Start the container
docker run --rm -it --name $CONTAINER_NAME --network host \
-e DISPLAY -e TERM -e QT_X11_NO_MITSHM=1 $IMG_NAME
# --rm: delete container after exiting
# -it: Interactive TTY mode so you can use a shell.
# --network host: Does not isolate Docker container from host's network interfaces.
# Allows all traffic to pass through as if it originated from the host.
# In our case, useful for DDS traffic for ROS.
# -e DISPLAY: Pass the X11 display through to the container.
# -e TERM: Pass the kind of terminal being used through to the container.
# -e QT_X11_NO_MITSHM=1: Disables shared memory extension for Qt/X11, which does not work consistently inside a process namespace like a container.
# -v "$XAUTHORITY:/.Xauthority": the $XAUTHORITY environment variable on the host contains the path to a file that grants access to X11.
# We mount the path defined in that environment variable into the container at /.Xauthority.
# -e XAUTHORITY=/.Xauthority: We set $XAUTHORITY *inside* the container to the place we just mounted the Xauthority (/.Xauthority)
docker run --rm -it --name $CONTAINER_NAME \
--network host \
-e DISPLAY \
-e TERM \
-e QT_X11_NO_MITSHM=1 \
-v "$XAUTHORITY:/.Xauthority" \
-e XAUTHORITY=/.Xauthority \
$IMG_NAME
21 changes: 19 additions & 2 deletions navigation2/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,22 @@ IMG_NAME=osrf/space_nav2
CONTAINER_NAME="$(tr '/' '_' <<< "$IMG_NAME")"

# Start the container
docker run --rm -it --name $CONTAINER_NAME --network host \
-e DISPLAY -e TERM -e QT_X11_NO_MITSHM=1 $IMG_NAME
# --rm: delete container after exiting
# -it: Interactive TTY mode so you can use a shell.
# --network host: Does not isolate Docker container from host's network interfaces.
# Allows all traffic to pass through as if it originated from the host.
# In our case, useful for DDS traffic for ROS.
# -e DISPLAY: Pass the X11 display through to the container.
# -e TERM: Pass the kind of terminal being used through to the container.
# -e QT_X11_NO_MITSHM=1: Disables shared memory extension for Qt/X11, which does not work consistently inside a process namespace like a container.
# -v "$XAUTHORITY:/.Xauthority": the $XAUTHORITY environment variable on the host contains the path to a file that grants access to X11.
# We mount the path defined in that environment variable into the container at /.Xauthority.
# -e XAUTHORITY=/.Xauthority: We set $XAUTHORITY *inside* the container to the place we just mounted the Xauthority (/.Xauthority)
docker run --rm -it --name $CONTAINER_NAME \
--network host \
-e DISPLAY \
-e TERM \
-e QT_X11_NO_MITSHM=1 \
-v "$XAUTHORITY:/.Xauthority" \
-e XAUTHORITY=/.Xauthority \
$IMG_NAME
21 changes: 19 additions & 2 deletions space_robots/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,22 @@ IMG_NAME=openrobotics/space_robots_demo
CONTAINER_NAME="$(tr '/' '_' <<< "$IMG_NAME")"

# Start the container
docker run --rm -it --name $CONTAINER_NAME --network host \
-e DISPLAY -e TERM -e QT_X11_NO_MITSHM=1 $IMG_NAME
# --rm: delete container after exiting
# -it: Interactive TTY mode so you can use a shell.
# --network host: Does not isolate Docker container from host's network interfaces.
# Allows all traffic to pass through as if it originated from the host.
# In our case, useful for DDS traffic for ROS.
# -e DISPLAY: Pass the X11 display through to the container.
# -e TERM: Pass the kind of terminal being used through to the container.
# -e QT_X11_NO_MITSHM=1: Disables shared memory extension for Qt/X11, which does not work consistently inside a process namespace like a container.
# -v "$XAUTHORITY:/.Xauthority": the $XAUTHORITY environment variable on the host contains the path to a file that grants access to X11.
# We mount the path defined in that environment variable into the container at /.Xauthority.
# -e XAUTHORITY=/.Xauthority: We set $XAUTHORITY *inside* the container to the place we just mounted the Xauthority (/.Xauthority)
docker run --rm -it --name $CONTAINER_NAME \
--network host \
-e DISPLAY \
-e TERM \
-e QT_X11_NO_MITSHM=1 \
-v "$XAUTHORITY:/.Xauthority" \
-e XAUTHORITY=/.Xauthority \
$IMG_NAME

0 comments on commit a8b90ca

Please sign in to comment.