基于Ubuntu 18.10构建含pdflatex的Docker镜像失败问题求助
问题根源
嘿,这个问题我太熟了!你碰到的核心问题是Ubuntu 18.10(代号Cosmic Cuttlefish)早就结束官方支持了——官方已经把它的软件源从主归档里移除了,所以apt-get update的时候才会一堆404,找不到对应的Release文件。
两种解决办法,任你选
办法1:改用Ubuntu旧版本归档源
如果一定要坚持用18.10的镜像,那我们可以把软件源替换成专门存放旧版本的归档服务器。修改你的Dockerfile如下:
FROM ubuntu:18.10 # 替换软件源为旧版本归档服务器 RUN sed -i 's/archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list && \ sed -i 's/security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list # 安装texlive相关包,加-y避免手动确认 RUN apt-get update && apt-get install -y \ texlive-fonts-recommended \ texlive-generic-recommended \ texlive-latex-extra \ texlive-fonts-extra \ dvipng \ texlive-latex-recommended \ texlive-base \ texlive-pictures \ texlive-lang-cyrillic \ texlive-science \ cm-super \ texlive-generic-extra CMD ["bash"]
办法2:升级到受支持的Ubuntu版本(更推荐)
其实更稳妥的是换用还在官方支持的Ubuntu版本,比如20.04或者22.04(都是长期支持版,能用到2025甚至2030年),源更稳定还能拿到安全更新。下面是基于20.04的Dockerfile示例:
FROM ubuntu:20.04 # 设置非交互式安装,避免构建时卡住 ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y \ texlive-fonts-recommended \ texlive-generic-recommended \ texlive-latex-extra \ texlive-fonts-extra \ dvipng \ texlive-latex-recommended \ texlive-base \ texlive-pictures \ texlive-lang-cyrillic \ texlive-science \ cm-super \ texlive-generic-extra # 可选:恢复默认的前端设置 ENV DEBIAN_FRONTEND=dialog CMD ["bash"]
验证步骤
改完Dockerfile后,重新跑构建命令:
docker build .
构建成功后,你可以启动容器测试pdflatex是否正常工作:
docker run -it <你的镜像ID> pdflatex --version
内容的提问来源于stack exchange,提问作者Demo_13B
相关产品推荐
相关产品推荐

