在Docker中添加Microsoft仓库遇APT源错误的解决方法
Docker构建时apt源列表格式错误排查与解决
问题详情
我尝试在Docker容器中安装Azure工具,参照官方文档编写了如下Dockerfile:
FROM --platform=linux/amd64 python:3.9-slim AS build RUN apt-get update \ && apt-get install --no-install-recommends -y \ build-essential \ curl \ gpg RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg RUN mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg RUN echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-$(lsb_release -cs)-prod $(lsb_release -cs) main" RUN sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/debian/$(lsb_release -rs | cut -d'.' -f 1)/prod $(lsb_release -cs) main" > /etc/apt/sources.list.d/dotnetdev.list' RUN apt-get update
执行最后一条apt-get update指令时出现错误:
> [ 7/11] RUN apt-get update: #10 0.835 E: Malformed entry 1 in list file /etc/apt/sources.list.d/dotnetdev.list (Component) #10 0.835 E: The list of sources could not be read.
我想查看生成的源列表文件内容来调试,但无法在构建过程中输出该内容。
解决方案
最终通过更换基础镜像解决了问题,修改后的基础镜像配置为:
FROM --platform=linux/amd64 python:3.9-slim-bullseye AS build
推测原基础镜像基于Alpine系统。
内容的提问来源于stack exchange,提问作者Luca
相关产品推荐
相关产品推荐

