Friday, November 12, 2021

[SOLVED] Docker build gives "There are no enabled repos" when running yum install

Issue

I am trying to dockerfy the installation guide described here:

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

I have created this minimal dockerfile:

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

But when I build it I get:

$ 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>

From the above guide I need to first add:

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

this to my dockerfile. Any input/examples on how to do that? I guess I basically need to copy the above text block into a /etc/yum.repos.d/mongodb.repo file on the image?

Edit: Based on below answer I can now docker ADD the repo file into the image and the above error is fixed. But I get this instead:

--> 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

Not sure if that is related to the repo information. I also tried to install openssl in dockerfile with:

RUN yum install openssl

but that gives:

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

Solution

Create a file in the same folder of your Dockerfile with the contents and add them to the image. Example:

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

Then in your 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


Answered By - Esteban Garcia