diff --git a/Dockerfile b/Dockerfile index e5ad882..9087494 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +# Stage 1 FROM mambaorg/micromamba:1.5.6 as micromamba-patched # Install security updates if base image is not yet patched # Inspired by https://pythonspeed.com/articles/security-updates-in-docker/ @@ -7,7 +8,7 @@ RUN apt-get update && apt-get -y upgrade # cat /etc/apt/sources.list # WORKDIR /etc/apt/ USER $MAMBA_USER - +# Stage 2 FROM micromamba-patched USER $MAMBA_USER COPY --chown=$MAMBA_USER:$MAMBA_USER env.yaml /tmp/env.yaml @@ -16,9 +17,6 @@ RUN micromamba install -y -n base -f /tmp/env.yaml && \ micromamba clean --all --yes WORKDIR /usr/app/src COPY --chown=$MAMBA_USER:$MAMBA_USER src/ ./ -# Attempt to make the external volume accessible on Linux systems -# Credits: https://stackoverflow.com/questions/66349101/docker-non-root-user-does-not-have-writing-permissions-when-using-volumes -# RUN mkdir /usr/app/data/output && chown -R $MAMBA_USER:$MAMBA_USER /usr/app/data/output ARG MAMBA_DOCKERFILE_ACTIVATE=1 ENTRYPOINT ["/usr/local/bin/_entrypoint.sh"] # For debugging, use this one diff --git a/build.sh b/build.sh index 2a95bba..bca8d9c 100755 --- a/build.sh +++ b/build.sh @@ -1,9 +1,16 @@ #!/usr/bin/env bash # Shell script for building Docker image -# Attempt to set the user ID etc. at build time did not change much -# docker build . -t mycromamba --build-arg="MAMBA_USER=$USER" \ -# --build-arg="MAMBA_USER_ID=$(id -u)" \ -# --build-arg="MAMBA_USER_GID=$(id -g)" +# It is possible to set UID, GID, and username to the matching +# user on the host by building a local image from mambaorg/micromamba +# git clone https://github.com/mamba-org/micromamba-docker.git +# cd micromamba-docker +# docker build . -t micromamba_local_user --build-arg="MAMBA_USER=$USER" \ +# --build-arg="MAMBA_USER_ID=$(id -u)" \ +# --build-arg="MAMBA_USER_GID=$(id -g)" +# and then change the base image in the Dockerfile from e.g. +# mambaorg/micromamba:1.5.6 +# to +# micromamba_local_user IMAGE_NAME="test_app" diff --git a/run_script.sh b/run_script.sh index 0302939..e867311 100755 --- a/run_script.sh +++ b/run_script.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash -# Shell script for starting Docker container -# TBD: - Check other useful Docker CLI options -# +# Shell script for starting Docker container with main.py +# TODO: - Check other useful Docker CLI options SOURCE_MOUNT="" NETWORK="--net=none"