############################## # General level requirements # ############################## # Pull official base image from DockerHub FROM python:2.7.18-slim-buster@sha256:6c1ffdff499e29ea663e6e67c9b6b9a3b401d554d2c9f061f9a45344e3992363 # Avoid interactive frontend ENV DEBIAN_FRONTEND="noninteractive" ################################## # Application level requirements # ################################## # Install required packages RUN INSTALL_PKGS="git gcc libssl-dev sqlite3" && \ apt-get -q clean && \ apt-get -q update && \ apt-get install -y $INSTALL_PKGS && \ apt-get -q clean ########################### # User level requirements # ########################### # Parameters for default user:group ARG uid=1000 ARG user=appuser ARG gid=1000 ARG group=appgroup # Add user and group for build and runtime # So the output can be owned by the specified uid:gid RUN grep -q ":${gid}:" /etc/group && { \ echo "Group ID ${gid} found"; \ } || { \ echo "Group ID ${gid} NOT found"; \ groupadd -g "${gid}" "${group}" && \ echo "Group ID ${gid} created"; \ } RUN id "${uid}" > /dev/null 2>&1 && { \ echo "User ID ${uid} found"; \ } || { \ echo "User ID ${uid} NOT found"; \ useradd -md "/home/${user}" -s /bin/bash -g "${group}" -u "${uid}" "${user}" && \ echo "User ID ${uid} created"; \ } # Switch to non-root user USER ${user} WORKDIR /home/${user} # Prepare user variables ENV USER ${user} ENV HOME=/home/${user} ENV PATH="${HOME}/.local/bin:${PATH}" ENV PYTHONPATH="." # Upgrade Pip RUN python -m pip install --disable-pip-version-check --no-cache --upgrade "pip==20.3.4" # Copy requirements COPY requirements.txt /home/${user}/requirements.txt # Install requirements RUN python -m pip install --user --no-cache --upgrade -r requirements.txt