How to enable YUM version lock in Amazon Linux 2 to prevent Docker 25 update

2 minute read
Content level: Intermediate

Docker 20.10, which was used in Amazon Linux 2 (AL2), reached its end-of-life in December 2023. This means that it will no longer receive any security updates going forward. If you do not want to upgrade to the newer Docker 25.0.3 version, we suggest that you lock your Docker package to the version you are currently using. You can do this using the shell script provided in the accompanying article.

Important Note: Please consider to create a full backup of your EC2 Instance with an Amazon Machine Image (AMI) or take snapshot of an idividual/multiple EBS volumes.

Run the following script to lock your current Docker version using the yum version lock. This will prevent your Docker package from being automatically updated to a newer version.


# Check if the user is running the script as root
if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root"
   exit 1

# Install the yum-plugin-versionlock package
yum install -y yum-plugin-versionlock

# Check if the installation was successful
if yum list installed yum-plugin-versionlock >/dev/null 2>&1; then
    echo "The yum-plugin-versionlock package has been installed successfully."
    echo "Failed to install the yum-plugin-versionlock package."
    exit 1

# Set the package name and version you want to lock

# Check if the package is installed
if yum list installed "$PACKAGE_NAME" >/dev/null 2>&1; then
    echo "Package $PACKAGE_NAME is installed on the system."
    echo "Package $PACKAGE_NAME is not installed on the system."
    exit 1

# Check if the package is already locked
if yum versionlock list | grep -q "$PACKAGE_NAME"; then
    echo "Version lock for $PACKAGE_NAME is already set."
    exit 0

# Lock the package version
yum versionlock add "$PACKAGE_NAME-$PACKAGE_VERSION"
if [ $? -eq 0 ]; then
    echo "Version lock for $PACKAGE_NAME-$PACKAGE_VERSION has been set successfully."
    echo "Failed to set version lock for $PACKAGE_NAME-$PACKAGE_VERSION."
    exit 1
profile pictureAWS
published 15 days ago1792 views