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

2 minute read
Content level: Intermediate
0

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.

#!/bin/bash

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

# 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."
else
    echo "Failed to install the yum-plugin-versionlock package."
    exit 1
fi

# Set the package name and version you want to lock
PACKAGE_NAME="docker"
PACKAGE_VERSION="*"

# 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."
else
    echo "Package $PACKAGE_NAME is not installed on the system."
    exit 1
fi

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

# 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."
else
    echo "Failed to set version lock for $PACKAGE_NAME-$PACKAGE_VERSION."
    exit 1
fi
profile pictureAWS
EXPERT
published 15 days ago1792 views