Docker 构建失败,"Package 'mongodb' has no installation candidate"



直到今天早上,构建我的容器是一个顺利的过程,现在我遇到了一些apt get -y mongodb问题。

我有一个非常简单的 Dockerfile,发布了相关代码,因为这是重现问题所需的全部内容。

FROM python:2.7
RUN apt-get update && 
apt-get -y install 
gpg 
mongodb 

我已经研究了一些修复程序,但它们似乎有点过火了,我应该只更改我的基本图像吗?我正在尝试了解此错误背后的原因以及如何将来证明它。

注意,我忘了放痕迹。

Sending build context to Docker daemon  1.354GB
Step 1/7 : FROM python:2.7
2.7: Pulling from library/python
5ae19949497e: Pull complete
ed3d96a2798e: Pull complete
f12136850781: Pull complete
1a9ad5d5550b: Pull complete
6f18049a0455: Pull complete
900d7861659d: Pull complete
536c9e631831: Pull complete
cb522be31b83: Pull complete
d03d3d7b603d: Pull complete
Digest: sha256:ee76dd856d06bdd734e1c3c816b243c984586629708f0a3e32038f94a891a5d8
Status: Downloaded newer image for python:2.7
---> 3edf9092825f
Step 2/7 : RUN apt-get update &&     apt-get -y install         gpg         mongodb         curl
---> Running in 870a931ec60c
Get:1 http://security.debian.org/debian-security buster/updates InRelease [39.1 kB]
Get:2 http://deb.debian.org/debian buster InRelease [118 kB]
Get:3 http://security.debian.org/debian-security buster/updates/main amd64 Packages [11.9 kB]
Get:4 http://deb.debian.org/debian buster-updates InRelease [46.8 kB]
Get:5 http://deb.debian.org/debian buster/main amd64 Packages [7897 kB]
Fetched 8113 kB in 4s (1805 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
Package mongodb is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'mongodb' has no installation candidate
The command '/bin/sh -c apt-get update &&     apt-get -y install         gpg         mongodb         curl' returned a non-zero code: 100

我猜你删除旧的python:2.7映像并重建你的dockerfile,或者只是更换另一台电脑来做构建。如果您使用新图像,您可以看到以下内容:

orange@orange:~$ docker images python:2.7
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
python              2.7                 3edf9092825f        8 hours ago         884MB

它显示图像是在 8 小时前创建的,因此使用的图像与您几天前使用的图像相比完全不同。

由此,如果您搜索python:2.7,您现在可能会看到它与2.7.16-buster,如您所知,几天前发布的debian buster,请参阅以下内容:

2019-07-06: 初始版本: 10.0 (新闻稿)

所以我想几天前,python:2.7是基于debian stretch的,所以在新的 debian 版本中,一些软件包被删除了,这会导致你的失败。

最佳实践:

你可以看到python dockerhub存储库中有Simple TagsShared Tags,请使用不会总是改变的Simple Tags,不要使用以后可能会标记到其他映像ID的Shared Tags,对于您的情况,请使用python:2.7.16-stretch。实际上,此基本映像是您过去使用的标记为python:2.7的映像,现在标记为python:2.7的映像不是您过去使用的映像。

相关内容

最新更新