web-dev-qa-db-ja.com

Jenkinsによるトリガー時のDocker許可エラーを解決する方法

私のJenkinsはDockerコンテナでは実行されず、VPSへの従来のインストールだけです。単純な テストプロジェクト を実行すると、次のエラーが発生しました。私はUbuntu 14、Java 7、安定したJenkinsを使用しています。Googleで見つけることができるすべての方法を試しましたが、機能しません。

このシェルを実行しようとしています

docker build --pull=true -t nick/hello-jenkins:$GIT_COMMIT .

コード変更後。

エラーは次のとおりです。

Got permission denied while trying to connect to the Docker daemon socket at unix: ....

Started by user nicolas xu
Building in workspace /var/lib/jenkins/workspace/hello-Jenkins
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.Origin.url https://github.com/nicolasxu/hello-nick-jenkins.git # timeout=10
Fetching upstream changes from https://github.com/nicolasxu/hello-nick-jenkins.git
 > git --version # timeout=10
 > git fetch --tags --progress https://github.com/nicolasxu/hello-nick-jenkins.git +refs/heads/*:refs/remotes/Origin/*
 > git rev-parse refs/remotes/Origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/Origin/origin/master^{commit} # timeout=10
Checking out Revision d94ae21a8a2cf58ffc790dcad15bd851fb17df5a (refs/remotes/Origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f d94ae21a8a2cf58ffc790dcad15bd851fb17df5a
 > git rev-list d94ae21a8a2cf58ffc790dcad15bd851fb17df5a # timeout=10
[hello-Jenkins] $ /bin/sh -xe /tmp/hudson5076309502904684976.sh
+ docker build --pull=true -t nick/hello-jenkins:d94ae21a8a2cf58ffc790dcad15bd851fb17df5a .
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.27/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&pull=1&rm=1&shmsize=0&t=nick%2Fhello-jenkins%3Ad94ae21a8a2cf58ffc790dcad15bd851fb17df5a&ulimits=null: dial unix /var/run/docker.sock: connect: permission denied
Build step 'Execute Shell' marked build as failure
Finished: FAILURE

コンソールで 'docker'をrootで問題なく実行できます。なぜjenkinsは 'docker'を実行するシェルコマンドを試すことができませんか?何が起こっている?完全に混乱している.......

17
Nicolas S.Xu

VPSサーバーターミナルで、これを実行してjenkinsユーザーをdockerグループに追加します。

Sudo usermod -aG docker jenkins

次に、jenkinsサーバーを再起動してグループを更新します。

これにより生じる可能性のあるセキュリティ上の問題を考慮してください。

警告:dockerグループは、rootユーザーと同等の特権を付与します。これがシステムのセキュリティに与える影響の詳細については、「Docker Daemon Attack Surface」を参照してください。

docs を参照してください


編集(@igerによる言及):コマンドラインからJenkinsを再起動する(つまり、Sudoサービスjenkinsを再起動する)だけで、残りのエンドポイント(http:/// restart)からではないことを確認してください

27
Robert
  1. here の説明に従って、ユーザーをdockerグループに追加します。
  2. 次のコマンドでジェンキンを起動します:docker run -d -u root --restart on-failure -p "8080:8080" -p "50000:50000" -v $PWD/jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean

rootユーザーが必要です。これがないと、ルートタスクを実行できなくなるためです。例:apk update && apk install ...

0
Denys Bushulyak