Running Chromium inside Docker - Gtk: cannot open display: :0

前端 未结 4 899
無奈伤痛
無奈伤痛 2020-12-12 23:45

When I try to run chromium inside a docker container I see the following error: Gtk: cannot open display: :0

Dockerfile: (based on https://registry.hub.docker.com/u/

相关标签:
4条回答
  • 2020-12-13 00:20

    Try

    xhost local:root
    

    This solve mine, I am on Debian Jessie. https://github.com/jfrazelle/dockerfiles/issues/4

    0 讨论(0)
  • 2020-12-13 00:27

    So, I also had a requirement to open a graphical application within my docker container. So, these are the steps that worked for my environment.(Docker version: 19.03.12 , Container OS: Ubuntu 18.04). Before running the container, make the host's X server accept connections from any client by running this command: xhost +. This is a very non-restrictive way to connect to the host's X server, and you can restrict as per the other answers given. Then, run the container with the --network=host option (E.g: docker run --network=host <my image name>). Once container is up, log in to its shell, and launch your app with DISPLAY=:0 (E.g: DISPLAY=:0 <my graphical app>)

    0 讨论(0)
  • 2020-12-13 00:35

    i don't know much about chromium, but, I did work with X way back when :-) When you tell an X client to connect to :0, what you are saying is connect to port 6000 (or whatever your X server runs on) + 0, or port 6000 in this case. In fact, DISPLAY is IP:PORT (with the +6000 as mentioned above). The X server is running on your host, so, if you set:

    DISPLAY=your_host_ip:0
    

    that might work. However, X servers did not allow connections from just any old client, so, you will need to open up your X server. on your host, run

    xhost +
    

    before running the docker container. All of this is assuming you can run chromium on your host (that is, an X server exists on your host).

    0 讨论(0)
  • 2020-12-13 00:45

    Adding as reference (see real answer from greg)

    In Docker image add

    RUN apt-get update
    RUN apt-get install -qqy x11-apps
    

    https://people.ece.cornell.edu/skand/post/x-forwarding-on-docker/

    and then run

    sudo docker run \
        --rm \ # delete container when bash exits
        -it \ # connect TTY
        --privileged \
        --env DISPLAY=unix$DISPLAY \ # export DISPLAY env variable for X server
        -v $XAUTH:/root/.Xauthority \ # provide authority information to X server
        -v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket
        -v /home/alex/coding:/coding \
        alexcpn/nvidia-cuda-grpc:1.0 bash
    

    check a sample command

    xclock
    
    0 讨论(0)
提交回复
热议问题