2

I'm trying to run google chrome from an lxc container, but it fails despite my repeated attempts and various tweaks.

ERROR:browser_main_loop.cc(271)] Gtk: cannot open display: :0.0

Here is my script

#!/bin/sh
CONTAINER=xenial-gui
CMD_LINE="google-chrome --disable-setuid-sandbox --user-data-dir $*"

STARTED=false

if ! lxc-wait -n $CONTAINER -s RUNNING -t 0; then
    lxc-start -n $CONTAINER -d
    lxc-wait -n $CONTAINER -s RUNNING
    STARTED=true
fi

PULSE_SOCKET=/home/ubuntu/.pulse_socket

lxc-attach --clear-env -n $CONTAINER -- sudo -u ubuntu -i \
    env DISPLAY=$DISPLAY PULSE_SERVER=$PULSE_SOCKET $CMD_LINE

if [ "$STARTED" = "true" ]; then
    lxc-stop -n $CONTAINER -t 10
fi
0

For me, it works, when doing xhost local:* as root or with sudo. This command allows access to the screen for local users. I need to issue this, because I'm running unprivileged containers as different user as I log into my desktop.

If you are running a non privileged container, you could even further restrict this with xhost local:username. See also man xhost.

When I started to experiment, I accidently had this enabled and wondered a while after restarting my machine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.