运行yum install时,Docker构建会给出“没有启用的存储库”

时间:2019-04-17 07:23:19

标签: docker yum

我正在尝试 dockerfy 此处描述的安装指南:

https://docs.opsmanager.mongodb.com/current/tutorial/install-simple-test-deployment/

我已经创建了这个最小的dockerfile:

FROM registry.access.redhat.com/rhel7/rhel:latest
RUN yum install -y mongodb-org mongodb-org-shell

但是当我构建它时,我得到了:

$ docker build . -t my-image
Sending build context to Docker daemon  22.53kB
Step 1/2 : FROM x.y.z:1234/rhel7/rhel:latest
 ---> 6979ec30598b
Step 2/2 : RUN yum install -y mongodb-org mongodb-org-shell
 ---> Running in d696383b761d
Loaded plugins: ovl, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
There are no enabled repos.
 Run "yum repolist all" to see the repos you have.
 To enable Red Hat Subscription Management repositories:
     subscription-manager repos --enable <repo>
 To enable custom repositories:
     yum-config-manager --enable <repo>

在上述指南中,我需要先添加:

echo "[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc" | sudo tee /etc/yum.repos.d/mongodb.repo

这到我的dockerfile。关于如何做到这一点的任何输入/示例?我想我基本上需要将上述文本块复制到图像上的/etc/yum.repos.d/mongodb.repo文件中?

编辑:基于以下答案,我现在可以将回购文件docker ADD 泊入映像,并且上面的错误已修复。但是我得到了这个:

--> Processing Dependency: openssl for package: mongodb-org-tools-4.0.9-1.el7.x86_64
--> Finished Dependency Resolution
Error: Package: mongodb-org-tools-4.0.9-1.el7.x86_64 (mongodb-org-4.0)
           Requires: openssl
Error: Package: mongodb-org-server-4.0.9-1.el7.x86_64 (mongodb-org-4.0)
           Requires: openssl
Error: Package: mongodb-org-shell-4.0.9-1.el7.x86_64 (mongodb-org-4.0)
           Requires: openssl
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
The command '/bin/sh -c yum install -y mongodb-org mongodb-org-shell' returned a non-zero code: 1

不确定是否与回购信息有关。我还尝试使用以下命令在dockerfile中安装openssl:

RUN yum install openssl

但这给出了:

No package openssl available.
Error: Nothing to do
The command '/bin/sh -c yum install openssl' returned a non-zero code: 1

1 个答案:

答案 0 :(得分:1)

Dockerfile的同一文件夹中创建包含内容的文件,并将其添加到图像中。示例:

cat <<EOF > mongodb.repo
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
EOF

然后在您的Dockerfile中:

FROM registry.access.redhat.com/rhel7/rhel:latest
ADD mongodb.repo /etc/yum.repos.d/mongodb.repo
RUN yum update && \
    yum install -y mongodb-org mongodb-org-shell