我试图通过 Jenkins 运行我的管道,但无法使用“sudo”执行任何命令。遇到 sudo 时出现以下错误:
sudo: 你在 passwd 数据库中不存在
按照我用来设置 Jenkins 从站的 Dockerfile。
FROM openjdk:8-jdk
RUN apt-get update -y && apt-get install -y curl sudo
#Install docker
RUN curl -sSL https://get.docker.com/ | sh
ARG user=jenkins
ARG group=jenkins
ARG uid=10000
ARG gid=10000
ENV HOME /home/${user}
RUN groupadd -g ${gid} ${group}
RUN useradd -c "Jenkins user" -d $HOME -u ${uid} -g ${gid} -m ${user}
RUN usermod -aG docker ${user}
RUN usermod -aG sudo ${user}
RUN usermod -aG root ${user}
ARG VERSION=3.20
ARG AGENT_WORKDIR=/home/${user}/agent
RUN apt-get install -y zip unzip sudo
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
RUN unzip awscliv2.zip
RUN ./aws/install -i /usr/local/aws-cli -b /usr/local/bin
RUN mkdir $HOME/.docker \
&& chmod 777 $HOME/.docker/
RUN curl --create-dirs -sSLo /usr/share/jenkins/slave.jar https://repo.jenkins-ci.org/public/org/jenkins-ci/main/remoting/${VERSION}/remoting-${VERSION}.jar \
&& chmod 755 /usr/share/jenkins \
&& chmod 644 /usr/share/jenkins/slave.jar
#docker compose cli
RUN curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/docker-compose
COPY jenkins-slave /usr/local/bin/jenkins-slave
RUN chmod 777 /usr/local/bin/jenkins-slave
RUN echo 'jenkins ALL=(ALL) NOPASSWD:ALL'| sudo EDITOR='tee -a' visudo
USER ${user}
ENV AGENT_WORKDIR=${AGENT_WORKDIR}
RUN mkdir /home/${user}/.jenkins && mkdir -p ${AGENT_WORKDIR}
VOLUME /home/${user}/.jenkins
VOLUME ${AGENT_WORKDIR}
WORKDIR /home/${user}
ENTRYPOINT ["/usr/local/bin/jenkins-slave"]