Make Jenkins run docker without sudo

后端 未结 4 861
小鲜肉
小鲜肉 2020-12-11 03:34

I would like to run Docker shell commands on Jenkins like:

docker ps

Is it possible to do it with out using any plugi

4条回答
  •  佛祖请我去吃肉
    2020-12-11 04:15

    Following approach worked for me to run docker commands without any plugins

    Rather than adding jenkins user to docker group, allowed jenkins user to run sudo commands with out prompting for password and then created an alias to avoid sudo in Dockerfile for jenkins slave. I had to install docker client in the container which connects to daemon running in the host machine.

    
     ## allowing jenkins user to run sudo commands
    RUN echo "jenkins ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
     ## avoid typing sudo in command line
    RUN echo "alias docker='sudo docker '" >> /home/jenkins/.bashrc
    

提交回复
热议问题