Errors related to OpenSSL 1.1.1 building Python 3.8.19 on CentOS 7 Docker Image

I’m using a Dockerfile to try to build a derived image of CentOS 7 that contains Python 3.8.19. I’ve been able to build Python 3.9, 3.10, and 3.11 using this same exact code but changing only the python version numbers. However, on Python 3.8, it fails and shows this during the make:

#9 270.6 gcc -pthread -shared -L/usr/lib64/openssl11 -Wl,-rpath=/usr/lib64/openssl11 -L/usr/lib64/openssl11 -L/usr/lib64/openssl11 -fPIE -I/usr/include/openssl11 build/temp.linux-x86_64-3.8/Python-3.8.19/Modules/_ctypes/_ctypes.o build/temp.linux-x86_64-3.8/Python-3.8.19/Modules/_ctypes/callbacks.o build/temp.linux-x86_64-3.8/Python-3.8.19/Modules/_ctypes/callproc.o build/temp.linux-x86_64-3.8/Python-3.8.19/Modules/_ctypes/stgdict.o build/temp.linux-x86_64-3.8/Python-3.8.19/Modules/_ctypes/cfield.o -L. -L/usr/lib64/openssl11 -L/usr/local/lib -lffi -ldl -o build/lib.linux-x86_64-3.8/_ctypes.cpython-38-x86_64-linux-gnu.so
#9 270.8
#9 270.8 The following modules found by detect_modules() in setup.py, have been
#9 270.8 built by the Makefile instead, as configured by the Setup files:
#9 270.8 _abc                  atexit                pwd
#9 270.8 time
#9 270.8
#9 270.8
#9 270.8 Failed to build these modules:
#9 270.8 _blake2               _ctypes_test          _xxtestfuzz

Later when I try to use pip or poetry I get:

#10 [7/9] RUN pip3.8 install --upgrade pip
#10 0.380 ERROR:root:code for hash blake2b was not found.
#10 0.380 Traceback (most recent call last):
#10 0.380   File "/usr/local/lib/python3.8/hashlib.py", line 251, in <module>
#10 0.380     globals()[__func_name] = __get_hash(__func_name)
#10 0.380   File "/usr/local/lib/python3.8/hashlib.py", line 126, in __get_openssl_constructor
#10 0.380     return __get_builtin_constructor(name)
#10 0.380   File "/usr/local/lib/python3.8/hashlib.py", line 120, in __get_builtin_constructor
#10 0.380     raise ValueError('unsupported hash type ' + name)
#10 0.380 ValueError: unsupported hash type blake2b
#10 0.380 ERROR:root:code for hash blake2s was not found.
#10 0.380 Traceback (most recent call last):
#10 0.380   File "/usr/local/lib/python3.8/hashlib.py", line 251, in <module>
#10 0.380     globals()[__func_name] = __get_hash(__func_name)
#10 0.380   File "/usr/local/lib/python3.8/hashlib.py", line 126, in __get_openssl_constructor
#10 0.380     return __get_builtin_constructor(name)
#10 0.380   File "/usr/local/lib/python3.8/hashlib.py", line 120, in __get_builtin_constructor
#10 0.380     raise ValueError('unsupported hash type ' + name)
#10 0.380 ValueError: unsupported hash type blake2s

Here’s my Dockerfile for the build:

FROM centos:7

ENV PATH="/usr/local/bin:$PATH"

RUN sed -i 's|^mirrorlist=|#mirrorlist=|g' /etc/yum.repos.d/CentOS-*
RUN sed -i 's|^#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

RUN yum -y install epel-release

RUN yum -y update && \
    yum -y install \
    openssl \
    openssl-devel \
    openssl11 \
    openssl11-devel \
    wget \
    bzip2-devel \
    libffi \
    libffi-devel \
    readline-devel \
    curl \
    llvm \
    xz \
    xz-devel \
    db4-devel \
    gdbm-devel \
    git \
    postgresql-devel \
    libxml2-devel \
    libxslt-devel \
    sqlite-devel \
    python3-devel \
    gcc \
    gcc-c++ \
    glibc-static \
    zlib-static \
    make \
    tk-devel \
    tcl-devel \
    libuuid-devel \
    python-pip && \
    yum clean all

# Set environment variables used by the compiler
ENV LDFLAGS="-L/usr/lib64/openssl11" \
    CPPFLAGS="-I/usr/include/openssl11" \
    CFLAGS="-fPIE" \
    LD_LIBRARY_PATH="/usr/local/lib"

RUN wget https://www.python.org/ftp/python/3.8.19/Python-3.8.19.tgz && \
    tar xzf Python-3.8.19.tgz && \
    cd Python-3.8.19 && \
    LDFLAGS="${LDFLAGS} -Wl,-rpath=/usr/lib64/openssl11" ./configure --with-openssl=/usr --enable-shared && \ 
    make -j$(nproc) && \
    make install && \
    cd / && \
    rm -rf Python-3.8.19 Python-3.8.19.tgz

RUN pip3.8 install --upgrade pip
RUN pip3.8 install poetry

RUN pip3.8 --version && \
    python3.8 --version && \
    poetry --version

CMD ["/bin/bash"]