fix: fix container slow caused by uid/gid

This commit is contained in:
watermeko
2026-07-24 07:46:45 +00:00
committed by Guoguo
parent c1986acf65
commit 7eee77a33d
3 changed files with 24 additions and 9 deletions

View File

@@ -6,7 +6,10 @@ RUN apt update \
&& apt install wget git cmake build-essential python3 python3-venv python3-pip autoconf automake libtool gosu -y
ARG DOCKER_USER=build
RUN useradd -m "$DOCKER_USER"
ARG DOCKER_UID=1000
ARG DOCKER_GID=1000
RUN groupadd --gid "$DOCKER_GID" "$DOCKER_USER" \
&& useradd --uid "$DOCKER_UID" --gid "$DOCKER_GID" --create-home --shell /bin/bash "$DOCKER_USER"
USER $DOCKER_USER
FROM base_apt AS host_tools
@@ -76,4 +79,4 @@ USER root
RUN chmod 0755 /entrypoint \
&& sed "s/\$DOCKER_USER/$DOCKER_USER/g" -i /entrypoint
ENTRYPOINT ["/entrypoint"]
ENTRYPOINT ["/entrypoint"]

14
docker/entrypoint Normal file → Executable file
View File

@@ -12,11 +12,19 @@ fi
if [ "$UID" != 0 ]
then
usermod -u "$UID" "$DOCKER_USER" 2>/dev/null && {
current_uid="$(id -u "$DOCKER_USER")"
current_gid="$(id -g "$DOCKER_USER")"
if [ "$current_uid" != "$UID" ]; then
usermod -u "$UID" "$DOCKER_USER"
fi
if [ "$current_gid" != "$GID" ]; then
groupmod -g "$GID" "$DOCKER_USER" 2>/dev/null ||
usermod -a -G "$GID" "$DOCKER_USER"
}
fi
set -- gosu "${UID}:${GID}" "${@}"
fi
exec "$@"
exec "$@"