代码之家  ›  专栏  ›  技术社区  ›  Hildy

在docker容器内运行Chromium browser时出错

  •  8
  • Hildy  · 技术社区  · 6 年前

    我创建了一个docker图像来运行Chromium浏览器。它工作得很好,我能够找到几乎所有出现问题的解决方案。然而,终端中显示了几个错误,我似乎无法找到解决方案。

    第一个错误是:

    [1:1:0329/015547.694703:错误:gpu\U process\U transport\U factory.cc(1019)]丢失UI共享上下文。

    另一个是:

    [1:216:0329/015547.823867:错误:bus.cc(394)]无法连接到总线:无法分析服务器地址:未知地址类型(有效类型的示例为“tcp”和UNIX上的“UNIX”)

    就功能而言,我还没有遇到过任何问题,但我无法处理不知道的问题。

    主持人:CentOS 7

    Dockerfile文件:

    FROM ubuntu:16.04
    COPY entrypoint.sh /sbin/entrypoint.sh
    RUN chmod 755 /sbin/entrypoint.sh
    ENTRYPOINT ["/sbin/entrypoint.sh"] 
    RUN apt-get update -y
    RUN apt-get install packagekit-gtk3-module -y
    RUN apt-get install libcanberra-gtk* -y
    RUN apt-get install chromium-browser -y
    RUN apt-get install xauth -y
    RUN apt-get upgrade -y
    RUN apt-get autoremove &&\
    apt-get clean &&\
        rm -rf /tmp/*
    

    入口点脚本:

    #!/bin/bash
    
    # Uses an envirnoment variable passed in at runtime by run_chromium.sh to add 
    username
    # that matches the host; if the account already exists, the script exits 
    and reminds the user
    # to comment out a section of run_gscan.sh
    useradd -m ${NEW_USER}
    if [[ "${?}" -ne 0 ]]
    then 
        echo "Account already created; starting gscan2pdf container"
        echo "If you have not already done so: "
        echo "Please comment out the indicated section in the 
        'gscan2pdf_run.sh' script"
        exit 0
    fi
    
    # If the host user's username was not already present, the following code 
    becomes reachable
    # and the follwing code adds the new user as a sudoer, as well as 
    matching the UID and GID in the 
    # image to that of the user's account on the host machine; this is 
    necessary for the method of 
    # accessing the host's XServer to work properly
    echo "${NEW_USER}:${NEW_USER}" | chpasswd && \
    usermod --shell /bin/bash ${NEW_USER} && \
    usermod -aG sudo ${NEW_USER} && \
    mkdir /etc/sudoers.d && \
    touch /etc/sudoers.d/${NEW_USER} && \
    echo "${NEW_USER} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/${NEW_USER} 
    && \
    chmod 0440 /etc/sudoers.d/${NEW_USER} && \
    usermod  --uid "${NEW_UID}" ${NEW_USER} && \
    groupmod --gid "${NEW_GID}" ${NEW_USER}
    
    # If the above code was reachable- because a matching user account was 
    not present at runtime -the 
    # user is instructed to comment out a section of the run_gscan.sh file 
    before the next run 
    echo "Account has been created to sync acces to the host's XServer."
    echo "Please comment out the indicated section in the 'run_gscan.sh' 
    script"
    

    最后,用于运行容器的脚本:

    #!/bin/bash   
    
    ########################################################
    # The following variables will be passed to the container at runtime:
    # the first two variables are used by the entrypoint.sh to create a 
    matching user account in the image  
    ######################################################
    HOST_UID=$(id -u)
    HOST_GID=$(id -g)
    
    
    #########################################################
    # The next two are used to expose the unix socket in the tmp directory 
    and an as-of-yet uncreated xauth
    # file in the container; since the tmp directory is not static, this is a 
    more secure approach
    
    ###########################################################
    XSOCK=/tmp/.X11-unix && 
    XAUTH=/tmp/.docker.xauth &&
    
    
    ############################################################
    # This creates the xauth file in the tmp directory mentioned above; then, 
    a series of piped commands
    # passes a numeric-format of authorization entry for the specified 
    display- :0 here -of to the sed
    # stream editor, then to the new Xauth file created by touch which uses 
    nmerge to merge the numeric-format
    # authorization entry to the newly created file the running container 
    will use t access the Xserver and 
    # dispay the GUI
    
    ##########################################################
    touch $XAUTH &&
    xauth nlist :0 | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge - &&
    
    # Comment out this section after first run  
    ##########################################################
    #docker run -e NEW_USER="${USER}" -e NEW_UID="${HOST_UID}" -e 
    #NEW_GID="${HOST_GID}" hildy:chromium 
    #LAST_CONTAINER=$(docker ps -lq) &&
    #docker commit "${LAST_CONTAINER}" hildy:chromium  
    ##########################################################
    
    ##########################################################
    # This is the command that will be run after the user account is created 
    above; not that the entrypoint
    # script- and ipso facto the default CMD in the image -ae overridden at 
    runtime and the applcation is 
    # launched instead
    
    ########################################################
    docker run \
    -ti \
    --user $USER \
    --privileged \
    -v /dev/snd:/dev/snd \
    -v /var/run/dbus:/var/run/dbus \
    -v $XAUTH:$XAUTH -v $XSOCK:$XSOCK \
    -e XAUTHORITY=$XAUTH -e DISPLAY \
    --entrypoint "" hildy:chromium chromium-browser --disable-gpu
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   Pierz    4 年前

    您可以尝试使用其 SwiftShader 软件渲染器,而不是 --disable-gpu 选项:

    chromium-browser --use-gl=swiftshader