gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:19:06 25 4
gpt4 key购买 nike

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

第一个错误是:

[1:1:0329/015547.694703:ERROR:gpu_process_transport_factory.cc(1019)] Lost UI shared context.



另一个是:

[1:216:0329/015547.823867:ERROR:bus.cc(394)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on 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

最佳答案

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

chromium-browser --use-gl=swiftshader

关于docker - 在docker容器中运行Chromium浏览器时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49547084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com