简体   繁体   中英

Dockerfile not installing google-chrome

I have written a Dockerfile based on python:3.9-slim-buster . I want to install chrome and chromedriver on top of this, but google-chrome package is not installing for some reason.

The Dockerfile:

FROM python:3.9-slim-buster

# set environment variables
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
# don't write .pyc files
ENV PYTHONDONTWRITEBYTECODE 1 
# prevent Docker from buffering stdout
ENV PYTHONUNBUFFERED 1 

# set working directory
WORKDIR /code

COPY ./requirements.txt .
 
# add key and repository
# RUN sudo apt install software-properties-common apt-transport-https wget ca-certificates gnupg2 -y

# install dependencies
RUN apt-get update && apt-get install -y \
  gnupg2 \
  unzip \
  wget

# chrome repo
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ 
    && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list

RUN apt-get update && apt-get install -y \
  gcc \
  google-chrome-stable \
  less \
  libmagickwand-dev \
  libpq-dev \
  python3-selenium \
  vim \
  # && wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip \
  # && unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/ \
    && rm -rf /var/lib/apt/lists/* \
    &&  pip install -r requirements.txt

# copy project
COPY . .

Command output for trying to find google-chrome :

root@f9832abc0069:/code# apt list --installed | grep google

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

root@f9832abc0069:/code# google-chrome
bash: google-chrome: command not found

How can I install google-chrome on my docker image?

 RUN apt-get update && apt-get install -y \

Yeah, IIRC, apt-get update will return a non-zero code when there's something to update (like other programs do when there's an error), so everything after the && never gets executed¹. So, use ; instead.


¹ I consider this a design bug in apt-get update , by the way, since it's hard to know whether an error occured, eg unreachable network or the desired outcome was achieved, and the system now knows what to update. The apt-get man page is a shame for the debian project, imho, because it specifies none of that.

I have copied your Dockerfile into an empty directory, then ran following commands inside:

$ cp /dev/null requirements.txt
$ docker build -t google-chrome .
$ docker run --rm -it -e DISPLAY=":0" -v /tmp/.X11-unix:/tmp/.X11-unix google-chrome google-chrome -no-sandbox

It worked without problem.

My environments:

$ docker -v
Docker version 20.10.17, build 100c701
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM