can‘t read /etc/apt/sources.list: No such file or directory

bash 复制代码
使用第二种方法现在直接报错了

(base) root@iZbp12r139zzzpzpwtqtqyZ:/opt/ppt_base# docker build -t ppt-base:latest -f Dockerfile .
[+] Building 0.5s (5/5) FINISHED                                                               docker:default
 => [internal] load build definition from Dockerfile                                                     0.0s
 => => transferring dockerfile: 367B                                                                     0.0s
 => [internal] load metadata for docker.io/library/python:3.11-slim                                      0.1s
 => [internal] load .dockerignore                                                                        0.0s
 => => transferring context: 2B                                                                          0.0s
 => CACHED [1/2] FROM docker.io/library/python:3.11-slim@sha256:8eb5fc663972b871c528fef04be4eaa9ab8ab45  0.0s
 => => resolve docker.io/library/python:3.11-slim@sha256:8eb5fc663972b871c528fef04be4eaa9ab8ab4539a5316  0.0s
 => ERROR [2/2] RUN sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list &&     apt-get  0.2s
------                                                                                                        
 > [2/2] RUN sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list &&     apt-get update &&     apt-get install -y --no-install-recommends         libreoffice-writer libreoffice-impress libreoffice-calc         fonts-dejavu imagemagick     && rm -rf /var/lib/apt/lists/*:
0.209 sed: can't read /etc/apt/sources.list: No such file or directory
------
Dockerfile:3
--------------------
   2 |     FROM python:3.11-slim
   3 | >>> RUN sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list && \
   4 | >>>     apt-get update && \
   5 | >>>     apt-get install -y --no-install-recommends \
   6 | >>>         libreoffice-writer libreoffice-impress libreoffice-calc \
   7 | >>>         fonts-dejavu imagemagick \
   8 | >>>     && rm -rf /var/lib/apt/lists/*
   9 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list &&     apt-get update &&     apt-get install -y --no-install-recommends         libreoffice-writer libreoffice-impress libreoffice-calc         fonts-dejavu imagemagick     && rm -rf /var/lib/apt/lists/*" did not complete successfully: exit code: 2
(base) root@iZbp12r139zzzpzpwtqtqyZ:/opt/ppt_base# 

对,这次的报错是合理的,不是网络问题,是我们"换源那一行"写得太老了:

bash 复制代码
sed: can't read /etc/apt/sources.list: No such file or directory

原因:现在的 python:3.11-slim 基于比较新的 Debian(bookworm/trixie),它已经用 /etc/apt/sources.list.d/debian.sources 这种新格式了,根本没有传统的 /etc/apt/sources.list,所以你一 sed 就报错。

给你一份能在这类 slim 镜像上跑的 兼容写法,直接用👇这个 Dockerfile:

bash 复制代码
FROM python:3.11-slim

# 1. 替换源(兼容老文件和 debian.sources)
RUN if [ -f /etc/apt/sources.list ]; then \
        sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list && \
        sed -i 's@security.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list ; \
    elif [ -f /etc/apt/sources.list.d/debian.sources ]; then \
        sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list.d/debian.sources && \
        sed -i 's@security.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list.d/debian.sources ; \
    else \
        echo "no apt source file found"; \
    fi \
    && apt-get update \
    && apt-get install -y --no-install-recommends \
        libreoffice-writer \
        libreoffice-impress \
        libreoffice-calc \
        fonts-dejavu \
        imagemagick \
    && rm -rf /var/lib/apt/lists/*

要点讲清楚:

  1. 先判断 /etc/apt/sources.list 在不在,在就 sed 它;

  2. 不在就改 /etc/apt/sources.list.d/debian.sources;

  3. 再 apt-get update,再装 libreoffice。

相关推荐
骚戴18 分钟前
n1n:从替代LiteLLM Proxy自建网关到企业级统一架构的进阶之路
人工智能·python·大模型·llm·gateway·api
秋氘渔21 分钟前
智演沙盘 —— 基于大模型的智能面试评估系统
python·mysql·django·drf
爱笑的眼睛1124 分钟前
超越AdamW:优化器算法的深度实现、演进与自定义框架设计
java·人工智能·python·ai
qq_3363139325 分钟前
java基础-stream流练习
java·开发语言·python
长安牧笛37 分钟前
设计职场新人社交恐惧破冰工具,生成趣味自我介绍模板,团建互动小游戏,帮助新人快速融入团队。
python
木泽八1 小时前
python实现pdf拆分与合并
服务器·python·pdf
拾贰_C1 小时前
[Python | pytorch | torchvision ] models like ResNet... 命名变量说明
开发语言·pytorch·python
清水白石0081 小时前
《Python 装饰器模式与代理模式深度剖析:从语法技巧到架构实战》
python·代理模式·装饰器模式
dagouaofei1 小时前
AI自动生成PPT工具横评,真实使用感受分享
人工智能·python·powerpoint
阿华田5121 小时前
如何基于Jupyter内核自研NoteBook
ide·python·jupyter·自研notebook