在docker容器中运行Chromium浏览器时出错

问题描述 投票:7回答:1

我创建了一个docker镜像来运行Chromium浏览器。它运作良好,而且我已经能够找到几乎所有出现的问题的解决方案。但是,终端中显示了一些错误,我似乎找不到解决方法。

第一个错误是:

[[1:1:0329 / 015547.694703:ERROR:gpu_process_transport_factory.cc(1019)]丢失的UI共享上下文。

另一个是:

[[1:216:0329 / 015547.823867:ERROR: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/*

Entrypoint脚本:

#!/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
docker ubuntu-16.04 centos7 chromium virtualization
1个回答
0
投票

[您可以尝试使用其SwiftShader软件渲染器而不是--disable-gpu选项来启动Chrome:

chromium-browser --use-gl=swiftshader
© www.soinside.com 2019 - 2024. All rights reserved.