mirror of
https://github.com/LamGC/jenkins-agent-with-docker.git
synced 2025-07-01 21:07:23 +00:00
修复构建镜像时所创建的 docker 用户组无效的问题。
This commit is contained in:
@ -4,7 +4,8 @@ FROM jenkins/inbound-agent:${BASE_TAG}
|
||||
|
||||
USER root
|
||||
|
||||
RUN groupadd -g 987 docker && usermod -aG docker jenkins
|
||||
COPY start-agent.sh /usr/local/bin/start.sh
|
||||
ENTRYPOINT [ "/usr/local/bin/start.sh" ]
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
ca-certificates \
|
||||
@ -16,5 +17,4 @@ RUN apt-get update && apt-get install -y \
|
||||
apt-get update && apt-get install -y docker-ce-cli docker-buildx-plugin docker-compose-plugin && \
|
||||
apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
USER jenkins
|
||||
|
||||
ENV DOCKER_HOST=unix:///var/run/docker.sock
|
||||
|
22
start-agent.sh
Normal file
22
start-agent.sh
Normal file
@ -0,0 +1,22 @@
|
||||
if [ $(whoami) != "jenkins" ] || [ $(id -u) == "0" ]; then
|
||||
echo "This script must be run as jenkins"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$GID" ]; then
|
||||
echo "GID is not set"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$UID" ]; then
|
||||
echo "UID is not set"
|
||||
exit 1
|
||||
fi
|
||||
if ! grep -q docker /etc/group; then
|
||||
groupadd -g $GID docker && usermod -aG docker jenkins
|
||||
fi
|
||||
if [ $(id -u jenkins) -ne $UID ]; then
|
||||
usermod -u $UID jenkins
|
||||
fi
|
||||
|
||||
# 使用传入的参数列表启动 Jenkins agent
|
||||
exec /usr/local/bin/jenkins-agent "$@"
|
Reference in New Issue
Block a user