How do I mount the CentOS 7 ISO and add it as a yum repository

The repo file is already present on your installed CentOS system, as /etc/yum.repos.d/CentOS-Media.repo.

[root@localhost ~]# cat /etc/yum.repos.d/CentOS-Media.repo 
# CentOS-Media.repo
#
#  This repo can be used with mounted DVD media, verify the mount point for
#  CentOS-7.  You can use this repo and yum to install items directly off the
#  DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
#  yum --enablerepo=c7-media [command]
#  
# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c7-media [command]

[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
        file:///media/cdrom/
        file:///media/cdrecorder/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Mount the ISO image at one of the given locations, or modify the file appropriately, then enable it as instructed.


Mount the iso

mount -o loop,ro centos7.iso /mnt/centos7-iso

Create this file /etc/yum.repos.d/repo.repo

[centos7-Server]
name=ServerFault Answer
baseurl=file:///mnt/centos7-iso
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1
gpgcheck=1

Then check if it worked with

yum list