I have the following jenkinsfile which is giving the error below.
node {
docker.withRegistry("https://001.dkr.ecr.eu-west-1.amazonaws.com/my-tooling") {
docker.image('my-tooling:deploy-agent_0.0.3')
.inside("-v /var/lib/jenkins/.ivy2:/home/jenkins/.ivy2", {
...
}
Error
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/my-tooling:deploy-agent_0.0.3/json: dial unix /var/run/docker.sock: connect: permission denied
I see lots of answers suggesting to run sudo usermod -aG docker $USER
but as I'm not running this locally and don't have access to the vm, because it's all infra-as-code how can I add this to the jenkinsfile?
I've tried to add it like this,
node {
try {
stage('set permissions') {
sh "sudo usermod -aG docker jenkins"
//also tried "sudo chmod 777 /var/run/docker.sock"
}
} finally {
echo 'Unable to set permissions'
}
...
}
But I'm not able to run sudo as I get the error..
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
sudo: no tty present and no askpass program specified
script returned exit code 1