首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有安装google-chrome的Dockerfile

没有安装google-chrome的Dockerfile
EN

Stack Overflow用户
提问于 2022-09-08 12:12:52
回答 2查看 137关注 0票数 0

我写了一个基于python:3.9-slim-buster的Dockerfile。我想安装铬和铬驱动器在此之上,但谷歌-铬软件包没有安装的原因。

Dockerfile:

代码语言:javascript
复制
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的命令输出

代码语言:javascript
复制
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

我如何在我的对接图像上安装谷歌-铬?

EN

回答 2

Stack Overflow用户

发布于 2022-09-08 12:16:32

运行apt-get更新&& apt-获取安装-y \

是的,IIRC,当有需要更新的内容时,apt-get update会返回一个非零的代码(就像其他程序有错误时所做的那样),所以&&之后的一切都不会被执行。所以,使用;代替。

顺便说一句,我认为这是apt-get update中的一个设计错误,因为很难知道是否发生了错误,例如无法到达的网络或预期的结果,而系统现在知道要更新什么。对于debian项目imho来说,apt-get手册页是一个耻辱,因为它没有指定所有这些。

票数 0
EN

Stack Overflow用户

发布于 2022-09-08 18:49:29

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

代码语言:javascript
复制
$ 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

没什么问题。

我的环境:

代码语言:javascript
复制
$ 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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73648925

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档