我写了一个基于python:3.9-slim-buster的Dockerfile。我想安装铬和铬驱动器在此之上,但谷歌-铬软件包没有安装的原因。
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我如何在我的对接图像上安装谷歌-铬?
发布于 2022-09-08 12:16:32
运行apt-get更新&& apt-获取安装-y \
是的,IIRC,当有需要更新的内容时,apt-get update会返回一个非零的代码(就像其他程序有错误时所做的那样),所以&&之后的一切都不会被执行。所以,使用;代替。
顺便说一句,我认为这是apt-get update中的一个设计错误,因为很难知道是否发生了错误,例如无法到达的网络或预期的结果,而系统现在知道要更新什么。对于debian项目imho来说,apt-get手册页是一个耻辱,因为它没有指定所有这些。
发布于 2022-09-08 18:49:29
我已经将您的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=focalhttps://stackoverflow.com/questions/73648925
复制相似问题