docker: Add support for UID:GID

Adds support for the UID/GID env variables in Docker via `gosu`.
This commit is contained in:
Dedy Martadinata S 2022-07-12 15:37:08 +07:00 committed by GitHub
parent 9a869a1474
commit 46546dac27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 5 deletions

View File

@ -56,13 +56,12 @@ ENV UID=1000
ENV GID=1000 ENV GID=1000
ENV USER=lldap ENV USER=lldap
RUN apt update && \ RUN apt update && \
apt install -y --no-install-recommends tini ca-certificates && \ apt install -y --no-install-recommends tini ca-certificates gosu && \
apt clean && \ apt clean && \
rm -rf /var/lib/apt/lists/* && \ rm -rf /var/lib/apt/lists/* && \
groupadd -g $GID $USER && useradd --system -m -g $USER --uid $UID $USER groupadd -g $GID $USER && useradd --system -m -g $USER --uid $UID $USER
COPY --from=lldap --chown=$CONTAINERUSER:$CONTAINERUSER /lldap /app COPY --from=lldap --chown=$CONTAINERUSER:$CONTAINERUSER /lldap /app
COPY --from=lldap --chown=$CONTAINERUSER:$CONTAINERUSER /docker-entrypoint.sh /docker-entrypoint.sh COPY --from=lldap --chown=$CONTAINERUSER:$CONTAINERUSER /docker-entrypoint.sh /docker-entrypoint.sh
WORKDIR /app WORKDIR /app
USER $USER
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"] ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]
CMD ["run", "--config-file", "/data/lldap_config.toml"] CMD ["run", "--config-file", "/data/lldap_config.toml"]

View File

@ -56,7 +56,8 @@ WORKDIR /app
ENV UID=1000 ENV UID=1000
ENV GID=1000 ENV GID=1000
ENV USER=lldap ENV USER=lldap
RUN apk add --no-cache tini ca-certificates bash && \ RUN echo http://mirror.math.princeton.edu/pub/alpinelinux/edge/testing/ >> /etc/apk/repositories && \
apk add --no-cache tini ca-certificates bash gosu && \
addgroup -g $GID $USER && \ addgroup -g $GID $USER && \
adduser \ adduser \
--disabled-password \ --disabled-password \
@ -69,6 +70,5 @@ RUN apk add --no-cache tini ca-certificates bash && \
COPY --from=lldap --chown=$CONTAINERUSER:$CONTAINERUSER /lldap /app COPY --from=lldap --chown=$CONTAINERUSER:$CONTAINERUSER /lldap /app
COPY --from=lldap --chown=$CONTAINERUSER:$CONTAINERUSER /docker-entrypoint.sh /docker-entrypoint.sh COPY --from=lldap --chown=$CONTAINERUSER:$CONTAINERUSER /docker-entrypoint.sh /docker-entrypoint.sh
WORKDIR /app WORKDIR /app
USER $USER
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"] ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]
CMD ["run", "--config-file", "/data/lldap_config.toml"] CMD ["run", "--config-file", "/data/lldap_config.toml"]

View File

@ -35,4 +35,13 @@ if [[ ! -r "$CONFIG_FILE" ]]; then
exit 1; exit 1;
fi fi
exec /app/lldap "$@" echo "> Setup permissions.."
find /app \! -user "$UID" -exec chown "$UID:$GID" '{}' +
find /data \! -user "$UID" -exec chown "$UID:$GID" '{}' +
echo "> Starting lldap.."
echo ""
exec gosu "$UID:$GID" /app/lldap "$@"
exec "$@"