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。

相关推荐
飞Link7 小时前
什么是 AirSim?一文读懂无人机仿真平台
python·算法·无人机
曲径海盗8 小时前
【Python 学习第 38 天】for 循环
python·学习笔记·编程入门
在世修行8 小时前
智学文枢:变式题生成引擎
python·ai·pyside·题目生成
On The Road :10 小时前
Java 多线程详解:从入门到线程安全
java·python·安全
岁月宁静10 小时前
如何设计支持 Skills 的 Agent?一套可扩展的四层架构
python·agent
岁月宁静10 小时前
CrewAI 快速上手:10 分钟搭建你的第一个 Agent 团队
python·agent
曲径海盗10 小时前
【Python 学习第 40 天】for 循环
python·学习笔记·编程入门
专注仿真11 小时前
知识问答大模型-rag算法详解
人工智能·python·控制算法
染指111011 小时前
158.Agent-LangGraph-子图(共享状态和不共享状态模式)
开发语言·人工智能·python·ui·agent·agents
云和数据.ChenGuang13 小时前
Python 常见特殊方法详解:__new__、__init__、__del__、__str__、__repr__ 与 __getattribute__
开发语言·人工智能·python·1024程序员节