我正在尝试在 docker 容器中安装 chrome。我执行:
RUN apt-get install -y wget
RUN wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb # problem here
RUN apt -f install -y
问题是
dpkg -i
由于缺少依赖项而失败。原则上这不是一个大问题,因为下一个命令应该解决这个问题,并且实际上它是在从容器内交互运行时做到的。但问题是,当构建 docker 容器时,此错误会使构建过程停止:
dpkg: error processing package google-chrome-stable (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:
google-chrome-stable
root@78b45ab9aa33:/#
exit
如何克服这个问题?有没有一种更简单的方法来安装 chrome 而不会引发依赖问题?我找不到要添加的存储库,因此我可以运行常规的
apg-get install google-chrome
,这就是我想做的。在
google linux 存储库中,他们只是提到“软件包将自动配置必要的存储库设置”。这不完全是我得到的......
实际上有
两种方法可以在 docker 容器上安装 Chrome: 如果您手动下载
deb文件,则可以使用apt-get
而不是
dpkg
来安装它。这将自动安装依赖项,而无需稍后调用 apt -f install -y
:RUN apt-get install -y wget
RUN wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt-get install -y ./google-chrome-stable_current_amd64.deb
另一个解决方案是添加存储库(安装 gpg 密钥)并直接从它们安装,跳过手动下载:
RUN apt-get install -y wget
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 -y install google-chrome-stable
FROM node:16.16.0 as base
# Chrome dependency Instalation
RUN apt-get update && apt-get install -y \
fonts-liberation \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libatspi2.0-0 \
libcups2 \
libdbus-1-3 \
libdrm2 \
libgbm1 \
libgtk-3-0 \
# libgtk-4-1 \
libnspr4 \
libnss3 \
libwayland-client0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxkbcommon0 \
libxrandr2 \
xdg-utils \
libu2f-udev \
libvulkan1
# Chrome instalation
RUN curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt-get install -y ./google-chrome-stable_current_amd64.deb
RUN rm google-chrome-stable_current_amd64.deb
# Check chrome version
RUN echo "Chrome: " && google-chrome --version
RUN apt -f install -y
RUN apt-get install -y wget
RUN wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt-get install ./google-chrome-stable_current_amd64.deb -y
有时,使用
wget
并不能解决问题。由于缺乏支持。所以你可以使用
apt -f install -y
@Pythonist 唯一的错误是命令混乱。
wget
或
gnupg
,工作如此充分
Dockerfile
FROM ubuntu:22.04
RUN apt-get update; apt-get clean
# Install wget.
RUN apt-get install -y wget
RUN apt-get install -y gnupg
# Set the 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
# Install Chrome.
RUN apt-get update && apt-get -y install google-chrome-stable
FROM python:3.11 as python-base
上面的答案对我有用(需要 --fix-missing)。
# Install chrome for python selenium
RUN apt -f install -y
RUN apt-get install -y wget
RUN wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt-get install ./google-chrome-stable_current_amd64.deb -y --fix-missing
apt-get
不起作用。
你应该使用dpkg -i ./google-chrome.deb