Running azure-cli docker image as non-root

Problem

You would like to be able to run the azure-cli docker image with a non-root user

Solution

Add the necessary package for Azure Linux 3.0 (shadow-utils) add a user and switch to this user:

FROM mcr.microsoft.com/azure-cli:azurelinux3.0

# Install required packages using tdnf
RUN tdnf install -y shadow-utils

# Create a non-root user
RUN useradd -m azureuser

# Switch to the new user
USER azureuser

WORKDIR /opt

COPY  ./script.sh /opt/

ENTRYPOINT ["sh", "script.sh"]