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?
2
Answers
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, e.g. unreachable network or the desired outcome was achieved, and the system now knows what to update. Theapt-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 :
It worked without problem.
My environments :