diff --git a/Dockerfile b/Dockerfile index ae2e50f..d3c7ea1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,10 +21,16 @@ LABEL vendor="MBARI" LABEL maintainer="dcline@mbari.org" LABEL license="Apache License 2.0" +ARG UID=1001 +ARG GID=1001 + # curl needed for health-check; clean apt in same layer to avoid bloating RUN apt-get update && apt-get install -y --no-install-recommends curl && \ apt-get clean && rm -rf /var/lib/apt/lists/* +RUN groupadd --gid ${GID} appuser && \ + useradd --uid ${UID} --gid ${GID} --no-create-home appuser + ENV PATH="/venv/bin:$PATH" ENV APP_HOME=/app ENV HF_HOME=/tmp/transformers_cache @@ -36,6 +42,10 @@ WORKDIR $APP_HOME COPY --from=builder /venv /venv COPY . . +RUN chown -R appuser:appuser /app /venv + +USER ${UID}:${GID} + EXPOSE 80 WORKDIR $APP_HOME/src/app CMD ["sh", "-c", "exec uvicorn main:app --host 0.0.0.0 --port 80 --ws-max-size 10485760"] diff --git a/Dockerfile.cuda b/Dockerfile.cuda index ed1175e..26484e9 100644 --- a/Dockerfile.cuda +++ b/Dockerfile.cuda @@ -33,6 +33,9 @@ LABEL vendor="MBARI" LABEL maintainer="dcline@mbari.org" LABEL license="Apache License 2.0" +ARG UID=1001 +ARG GID=1001 + RUN apt-get update && \ apt-get install -y --no-install-recommends software-properties-common && \ add-apt-repository ppa:deadsnakes/ppa && \ @@ -42,6 +45,9 @@ RUN apt-get update && \ curl libxcb1 libxcb-xinerama0 libxrender1 libxext6 libsm6 libice6 libgl1 && \ apt-get clean && rm -rf /var/lib/apt/lists/* +RUN groupadd --gid ${GID} appuser && \ + useradd --uid ${UID} --gid ${GID} --no-create-home appuser + ENV PATH="/venv/bin:$PATH" ENV APP_HOME=/app ENV HF_HOME=/tmp/transformers_cache @@ -55,6 +61,10 @@ WORKDIR $APP_HOME COPY --from=builder /venv /venv COPY . . +RUN chown -R appuser:appuser /app /venv + +USER ${UID}:${GID} + ARG NUM_WORKERS=1 ENV NUM_WORKERS=${NUM_WORKERS} EXPOSE 80