Dockerfile: RUN yum install -y package_name generates error message

I am using Docker version 23.0.1, build a5ee5b1. My Dockerfile has only this:

FROM rockylinux/rockylinux
RUN yum install -y aide.x86_64
RUN yum install -y ansible.noarch

The output :

$ docker build . --progress plain
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 130B done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 transferring context: 2B done
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/rockylinux/rockylinux:latest
#3 DONE 0.9s

#4 [1/3] FROM docker.io/rockylinux/rockylinux@sha256:fc370d748f4cd1e6ac3d1b6460fb82201897fa15a16f43e947940df5aca1a56e
#4 DONE 0.0s

#5 [2/3] RUN yum install -y aide.x86_64
#5 CACHED

#6 [3/3] RUN yum -y install ansible.noarch
#6 0.960 Last metadata expiration check: 0:02:37 ago on Thu Jun 22 19:36:57 2023.
#6 1.454 No match for argument: ansible.noarch
#6 1.469 Error: Unable to find a match: ansible.noarch
#6 ERROR: process "/bin/sh -c yum -y install ansible.noarch" did not complete successfully: exit code: 1
------
 > [3/3] RUN yum -y install ansible.noarch:
#6 0.960 Last metadata expiration check: 0:02:37 ago on Thu Jun 22 19:36:57 2023.
#6 1.454 No match for argument: ansible.noarch
#6 1.469 Error: Unable to find a match: ansible.noarch
------
Dockerfile:3
--------------------
   1 |     FROM rockylinux/rockylinux
   2 |     RUN yum install -y aide.x86_64
   3 | >>> RUN yum -y install ansible.noarch
   4 |
   5 |
--------------------
ERROR: failed to solve: process "/bin/sh -c yum -y install ansible.noarch" did not complete successfully: exit code: 1

Yes, ansible.noarch is there.

If I try to run
/bin/sh -c yum install -y ansible.noarch
I get the help message for yum.

If I try to run
yum install -y ansible.noarch
It will work.

If I try to run
/bin/sh -c "yum install -y ansible.noarch"
It will work.

It worked doing a “RUN yum install -y aide.x86_64” but won’t work trying to install ansible.noarch.

What is going on?

Using dnf instead of yum returns the same error message.

I also tried this form:
RUN [“dnf”,“-y”,“install”,“ansible”]

Got:
ERROR: failed to solve: process “dnf -y install ansible” did not complete successfully: exit code: 1

Where? It is not available in the repository using the image you shared.

Because you try to run only “yum” in the shell and pass the arguments yum to /bin/sh which doesn’t know anything about that. The error message doesn’t show you what command was actually running because this should have been the actual error message:

ERROR: process '/bin/sh -c "yum -y install ansible.noarch"' did not complete successfully: exit code: 1

These are indeed correct commands, although I don’t see why it would work. Can you show the result of a working version?

By the way you are actualy using an old image. The developers forgot to remove the latest tag and what makes it worse is that they claim in the description that the latest tag is always the most recent image.

https://hub.docker.com/r/rockylinux/rockylinux

Rocky Linux image documentation

The rockylinux/rockylinux:latest tag is always the most recent version currently available.

which is clarly not true.

https://hub.docker.com/r/rockylinux/rockylinux/tags?page=1&name=latest

At least that version has an ansible package but with a different name

 »  docker run --rm -it localhost/test bash
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
[root@5705aa3a90a6 /]# yum search ansible
Last metadata expiration check: 0:21:07 ago on Thu Jun 22 20:46:46 2023.
=========================================================================== Name & Summary Matched: ansible ===========================================================================
ansible-collection-microsoft-sql.noarch : The Ansible collection for Microsoft SQL Server management
ansible-collection-redhat-rhel_mgmt.noarch : Ansible Collection of general system management and utility modules and other plugins
ansible-freeipa-tests.noarch : ansible-freeipa tests
ansible-pcp.noarch : Ansible Metric collection for Performance Co-Pilot
ansible-test.x86_64 : Tool for testing ansible plugin and module code
centos-release-ansible-29.noarch : Ansible 2.9 packages from the CentOS ConfigManagement SIG repository
================================================================================ Name Matched: ansible ================================================================================
ansible-core.x86_64 : SSH-based configuration management, deployment, and task execution system
ansible-freeipa.noarch : Roles and playbooks to deploy FreeIPA servers, replicas and clients

You can find these in the list:

centos-release-ansible-29.noarch : Ansible 2.9 packages from the CentOS ConfigManagement SIG repository
ansible-core.x86_64 : SSH-based configuration management, deployment, and task execution system

In case of recent Ansible versions there is a core package and another package usually called “ansible” that contains community developed collections. If you use the latest rockylinux/rockylinux image (not the latest tag but version 9), there is no `centos-release-ansible-*" package at all.

ou don’t need one as you can instal Ansible as I always do, using Python’s package manager, pip.

FROM rockylinux/rockylinux:9
RUN yum install -y aide.x86_64 python3-pip
RUN pip install ansible==8.1.0
docker build . -t localhost/test
 »  docker run --rm -it localhost/test ansible --version
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
ansible [core 2.15.1]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.16 (main, Dec  8 2022, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Or follow instructions like this about using the epel-repo:

There is also an “official” rockylinux Docker image: https://hub.docker.com/_/rockylinux

which doesn’t have latest tag at all.

Turned out to be pretty simple to resolve once I had a good night’s sleep.

First of all I created a Docker pod using “docker run -it image_name bash” and tried running the commands one-by-one. Funny, I got the same errors. :grinning:

Then I looked on hub.docker.com and noticed that I wasn’t using the most popular image which is called “rockylinux”. I also noticed that this image has no “latest” tag so I used a tag of “9”. Now I have a Dockerfile of this:

FROM rockylinux:9

RUN dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
RUN dnf -y update

RUN dnf install -y ansible
RUN dnf -y install aide.x86_64

And this worked!

BTW: EPEL is required for ansible to install.

You basically described exactly what I wrote in my previous answer except

Not if you just install pip and install ansible using pip.

I am wondering if you read my previous answer, because your last comment indicates that you found out everything alone and you didn’t react on my recommendation regarding python3-pip.

I can’t use python3-pip. The company policy does not allow “extra” packages to be installed. Gotta use what is there on my very restrictive list.