如何在Python官方Docker镜像中安装libappindicator1以部署Google Chrome
报错原因
你使用的python:3.9官方镜像基于Debian 12(Bookworm)版本,Debian从11(Bullseye)开始已将libappindicator1从官方默认源移除,因此直接执行apt安装会触发找不到包的错误。
解决方案
方案1:使用兼容替代包(推荐)
libayatana-appindicator1是libappindicator1的官方兼容替代包,Chrome可以正常识别该依赖,无需添加额外源,稳定性更高。修改后的Dockerfile示例如下:
FROM python:3.9 # 安装系统依赖,用libayatana-appindicator1替代废弃的libappindicator1 RUN apt-get update && apt-get install -y --no-install-recommends \ gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 \ libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation \ libayatana-appindicator1 libnss3 lsb-release xdg-utils fonts-takao-* \ && rm -rf /var/lib/apt/lists/* # 安装Chrome RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \ && dpkg -i google-chrome-stable_current_amd64.deb \ && apt-get -fy install \ && rm google-chrome-stable_current_amd64.deb \ && rm -rf /var/lib/apt/lists/*
注:添加
--no-install-recommends和清理apt缓存的操作可以有效缩小镜像体积。
方案2:安装原版libappindicator1(仅特殊需求使用)
如果必须使用原版libappindicator1,可以先添加Debian旧版本的universe源再安装,修改后的Dockerfile示例如下:
FROM python:3.9 # 添加Debian旧稳定版源获取已下架的libappindicator1 RUN echo "deb http://deb.debian.org/debian oldstable main universe" >> /etc/apt/sources.list \ && apt-get update \ && apt-get install -y --no-install-recommends \ gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 \ libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation \ libappindicator1 libnss3 lsb-release xdg-utils fonts-takao-* \ && rm -rf /var/lib/apt/lists/* # 安装Chrome RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \ && dpkg -i google-chrome-stable_current_amd64.deb \ && apt-get -fy install \ && rm google-chrome-stable_current_amd64.deb \ && rm -rf /var/lib/apt/lists/*
内容的提问来源于stack exchange,提问作者Nori
相关产品推荐
相关产品推荐

