How to install google-chrome by command line so it can be used by selenium inside a python docker image?

  docker, google-chrome, python, selenium

I want to install google-chrome inside a python docker image, so I can use that with selenium. I tried the following commands:

curl https://dl-ssl.google.com/linux/linux_signing_key.pub -o /tmp/google.pub
cat /tmp/google.pub | apt-key add -
rm /tmp/google.pub 
echo 'deb http://dl.google.com/linux/chrome/deb/ stable main' > /etc/apt/sources.list.d/google.list
mkdir -p /usr/share/desktop-directories 
apt-get -y update 
apt-get install -y google-chrome-stable
dpkg-divert --add --rename --divert /opt/google/chrome/google-chrome.real /opt/google/chrome/google-chrome
echo "#!/bin/bashnexec /opt/google/chrome/google-chrome.real --no-sandbox --disable-setuid-sandbox "[email protected]"" > /opt/google/chrome/google-chrome
chmod 755 /opt/google/chrome/google-chrome
google-chrome --version

but the last command raises an error:

/bin/bash: /usr/bin/google-chrome: /bin/bashnexec: bad interpreter: No such file or directory

Maybe there is a more easy way, or a simplified way to just set up what is needed by selenium? Or just any way that works?

Source: Docker Questions

LEAVE A COMMENT