【问题标题】:Docker build failing with "Package 'mongodb' has no installation candidate"Docker 构建失败并显示“包 'mongodb' 没有安装候选者”
【发布时间】:2019-07-13 21:31:12
【问题描述】:

直到今天早上,我的容器构建过程都很顺利,现在我遇到了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

【问题讨论】:

    标签: mongodb docker docker-compose mongodb-query containers


    【解决方案1】:

    我猜你删除了旧的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 小时前创建的,因此使用的图像与您几天前使用的图像有很大不同。

    来自this,如果你搜索python:2.7,你现在可能会看到和2.7.16-buster一样,如你所知,debian buster是几天前发布的,见this

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

    所以我猜几天前,python:2.7 是基于debian stretch,所以在新的 debian 版本中,删除了一些包,导致您的失败。

    最佳实践:

    您可以在 python dockerhub repo 中看到Simple TagsShared Tags,请使用Simple Tags,它不会总是改变,不要使用Shared Tags,它可能会在以后标记到其他图像ID,以适合您的情况, 使用python:2.7.16-stretch。事实上,这个基础镜像是你过去使用的标记为python:2.7 的那个,现在标记为python:2.7 的那个不是你过去使用的那个。

    【讨论】:

      猜你喜欢
      • 2016-08-01
      • 1970-01-01
      • 2018-08-09
      • 2018-05-25
      • 1970-01-01
      • 2019-07-01
      • 2020-03-27
      • 2021-04-23
      • 2020-02-02
      相关资源
      最近更新 更多