Your URL is wrong, the following worked for me:
RUN curl http://mirror.centos.org/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7 -o RPM-GPG-KEY-CentOS-7
RUN rpm --import RPM-GPG-KEY-CentOS-7
RUN yum-config-manager --add-repo='http://mirror.centos.org/centos/7/os/x86_64/'
Note that a lot of their packages will conflict with Amazon's pre-installed packages.
One workaround I've found is to not add that repo, and instead use yum install <direct_rpm_link> for all of my installations. I had to manually resolve some dependencies myself by adding more .rpm links, but at least it worked in the end.
Add centos repository to Amazon Linux instance - Stack Overflow
amazon web services - need help to install php 7.2 yum packages on aws ec2 - Stack Overflow
Amazon Linux Extras versus EPEL
I've tested installing a few packages from EPEL for Enterprise Linux 7. Make sure you do use the EL7 version, since Amazon Linux 2 is systemd based:
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
amazon-linux-extras only has a few packages for now, so if that's all you need, great. Depending on the packages you install, you always run the risk of conflicts between EPEL and Amazon repos.
More on reddit.comHow do I figure out what CentOS version my AMazon Linux distribution is based on? - Unix & Linux Stack Exchange
Videos
Instead of guessing which version of RHEL a particular distro is based off, just run:
rpm -E %{rhel}
For Amazon Linux 2, this will give you 7.
There's a discussion thread available over on the AWS forums that indicates the officially supported Amazon Linux AMI is not based upon any Linux distribution. Rather, the Amazon Linux AMI is independently maintained image by Amazon.
Although the @amzn-main repo doesn't have PHP 7.2 yet (as far as I know), you can use remi-php72. According to his release blog you can install the EPEL and Remi repositories via:
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
wget http://rpms.remirepo.net/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6.rpm
rpm -Uvh epel-release-latest-6.noarch.rpm
And then enable remi-php72 using yum-config-manager:
yum install yum-utils
yum-config-manager --enable remi-php72
After that, you can simply search and install php and all the needed extensions like normal:
sudo yum install --disablerepo="*" --enablerepo="remi,remi-php72" php php-fpm php-cli ...
As @Typel says in a comment on the other answer - if you're using Amazon Linux 2 AMI then
sudo amazon-linux-extras install -y php7.2
Beats installing multiple external repos and has most of th basics, including mariadb and vim (everything I need to feel happy!).
See the list: sudo amazon-linux-extras list
I'm taking an initial look at Amazon Linux 2, and see that the EPEL repo is not available by default. I've read the FAQ about Extras, but this seems more akin to Software Collections (SCL) than EPEL.
Has anyone enabled EPEL for Linux 2, and if so, are you using the standard Redhat 7 EPEL, or a different repo?
Thanks.
you can get the centos/rhel version details from the file "/proc/version"
to get the version detail alone then you can grep like this
echo "Red Hat:`cat /proc/version | awk -F "Red Hat" '{print $2}' | awk -F ")" '{print $1}'`"
else using rpm
rpm -E %{rhel}
Found this on server fault. https://serverfault.com/questions/798427/what-linux-distribution-is-the-amazon-linux-ami-based-on
To sum up: Quote from AWS folks :
The Amazon Linux AMI is not based on any one upstream Linux project. That said, one of the goals of the most current Amazon Linux AMI (2013.09) is to be as compatible as possible with RHEL 6. If there are places in which you find that we are not, please let us know so that we can investigate further."