Dockerfile没有安装谷歌chrome



我已经编写了一个基于python:3.9-slim-buster的Dockerfile。我想在上面安装chrome和chromedriver,但谷歌chrome包由于某种原因没有安装。

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 . .

尝试查找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

如何在docker镜像上安装google chrome?

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

是的,IIRC、apt-get update在有更新时会返回一个非零代码(就像其他程序在出现错误时所做的那样(,所以&&之后的所有内容永远不会被执行。因此,请改用;


顺便说一句,我认为这是apt-get update中的一个设计错误,因为很难知道是否发生了错误,例如无法访问的网络或实现了所需的结果,而且系统现在知道要更新什么。apt-get手册页是debian项目imho的耻辱,因为它没有指定任何内容。

我已经将Dockerfile复制到一个空目录中,然后在里面运行以下命令:

$ 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

它工作起来没有问题。

我的环境:

$ 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

最新更新