Skip to main content
 首页 » 编程设计

基于r-base docker镜像docker build时Python包安装问题

2024年12月31日25kenshinobiy

我想在 r-base docker 镜像中安装 python。当我尝试这个时:

FROM r-base:3.4.1 
RUN apt-get update && apt-get install -y python3  

我得到错误:

Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages. 

当我尝试这样做时:

FROM r-base:3.5.1 
RUN apt-get update && apt-get install -y python3  

我得到错误:

The repository 'http://deb.debian.org/debian testing Release' does not have a Release file. 

如果我从 jupyter notebook base 开始,我可以同时使用 R 和 Python,但我真的希望这个图像更 slim ,所以我想从 r-base 开始。请注意,USER root 也没有解决这些问题。

请您参考如下方法:

看到这个真的很奇怪link

The server deb.debian.org does not have packages itself, but the name has SRV records in DNS that let apt in stretch and later find places.

也许您的本地网络比较特殊,例如:

If you hit the server behind deb.debian.org directly, either because you use an older apt or because you use a HTTP proxy that does not support SRV records, your requests will get HTTP redirected to one of the CDN instances. If you want to avoid the redirects, you can pick one instance directly.

因此,建议在您的 Dockerfile 中添加 apt 的直接源,如下所示:

FROM r-base:3.5.1 
 
RUN echo "deb http://cdn-fastly.deb.debian.org/debian stable main" > /etc/apt/sources.list && \ 
  echo "deb http://cdn-fastly.deb.debian.org/debian-security stable/updates main" >> /etc/apt/sources.list && \ 
  rm -fr /etc/apt/apt.conf.d/default && \ 
  apt-get update && apt-get install -y python3 

如果你有代理,请在 Dockerfile 中添加类似 ENV http_proxy "http://your_proxy" 的内容,希望对你有帮助。