Created
July 5, 2022 17:55
-
-
Save yen3/b5fcdfffd441ab43c401ad108ed5fc72 to your computer and use it in GitHub Desktop.
A tiny example: Execute "notify-send" from container to send messages to host
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# ref: https://forums.docker.com/t/communicate-with-dbus-from-an-unprivileged-container/101549 | |
# ref: https://stackoverflow.com/questions/23601844/how-to-create-user-in-linux-by-providing-uid-and-gid-options | |
# ref: https://github.com/mviereck/x11docker/wiki/How-to-connect-container-to-DBus-from-host | |
set -euxo pipefail | |
readonly DBUS_USER_SESSION_PATH="${DBUS_SESSION_BUS_ADDRESS#"unix:path="}" | |
readonly uid=$(id -u) | |
readonly gid=$(id -g) | |
docker run -it \ | |
--rm \ | |
--privileged \ | |
--security-opt "apparmor:unconfined" \ | |
--cap-add ALL \ | |
-v /var/run/dbus:/var/run/dbus \ | |
-e DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS" \ | |
-v "${DBUS_USER_SESSION_PATH}:${DBUS_USER_SESSION_PATH}" \ | |
ubuntu:22.04 \ | |
/bin/bash -c "apt update && apt install -y libnotify-bin && groupadd -g ${gid} user && useradd user -u ${uid} -g ${gid} -m -s /bin/bash && su user -s /bin/bash -c '/usr/bin/notify-send test-1'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment