Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors when running Chromium browser inside docker container

I have created a docker image to run the Chromium browser. It works well and I've been able to track down a solution to nearly every issue that has popped up. However, there are a couple of errors that display in the terminal that I can't seem to find a solution for.

The first error is:

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

The other is:

[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")

I haven't experienced any problems (yet) as far as functionality is concerned, but I can't handle the not-knowing.

Host: 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 script:

#!/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"

Finally, the script that's used to run a container:

#!/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
like image 615
Hildy Avatar asked Mar 29 '18 02:03

Hildy


Video Answer


1 Answers

You could try starting Chrome using its SwiftShader software renderer instead of the --disable-gpu option:

chromium-browser --use-gl=swiftshader
like image 150
Pierz Avatar answered Sep 29 '22 19:09

Pierz