Can you run GUI applications in a Docker container?

前端 未结 22 2861
南旧
南旧 2020-11-22 06:12

How can you run GUI applications in a Docker container?

Are there any images that set up vncserver or something so that you can - for example - add an e

22条回答
  •  猫巷女王i
    2020-11-22 06:23

    I'm late to the party, but for Mac users who don't want to go down the XQuartz path, here is a working example that builds a Fedora Image, with a Desktop Environment (xfce) using Xvfb and VNC. It's simple, and works:

    • https://github.com/ddual/docker_recipes#fedora-with-an-x-window-system
    • https://github.com/ddual/docker_recipes/tree/master/fedora_gui

    On a Mac, you can just access it using the Screen Sharing (default) application, connecting to localhost:5901.

    Dockerfile:

    FROM fedora
    
    USER root
    
    # Set root password, so I know it for the future
    RUN echo "root:password123" | chpasswd
    
    # Install Java, Open SSL, etc.
    RUN dnf update -y --setopt=deltarpm=false  \
     && dnf install -y --setopt=deltarpm=false \
                    openssl.x86_64             \
                    java-1.8.0-openjdk.x86_64  \
                    xorg-x11-server-Xvfb       \
                    x11vnc                     \
                    firefox                    \
                    @xfce-desktop-environment  \
     && dnf clean all
    
    # Create developer user (password: password123, uid: 11111)
    RUN useradd -u 11111 -g users -d /home/developer -s /bin/bash -p $(echo password123 | openssl passwd -1 -stdin) developer
    
    # Copy startup script over to the developer home
    COPY start-vnc.sh /home/developer/start-vnc.sh
    RUN chmod 700 /home/developer/start-vnc.sh
    RUN chown developer.users /home/developer/start-vnc.sh
    
    # Expose VNC, SSH
    EXPOSE 5901 22
    
    # Set up VNC Password and DisplayEnvVar to point to Display1Screen0
    USER developer
    ENV  DISPLAY :1.0
    RUN  mkdir ~/.x11vnc
    RUN  x11vnc -storepasswd letmein ~/.x11vnc/passwd
    
    WORKDIR /home/developer
    CMD ["/home/developer/start-vnc.sh"]
    

    start-vnc.sh

    #!/bin/sh
    
    Xvfb :1 -screen 0 1024x768x24 &
    sleep 5
    x11vnc -noxdamage -many -display :1 -rfbport 5901 -rfbauth ~/.x11vnc/passwd -bg
    sleep 2
    xfce4-session &
    
    bash
    # while true; do sleep 1000; done
    

    Check the linked readme for build and run commands if you want/need.

提交回复
热议问题