docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run

jenkins pipeline在调用docker命令执行创建容器动作时报错如下:

17:30:47  ==============================check_docker_status==============================
[Pipeline] sh
17:30:47  + docker run -it -d -v /home/dell/workspace/workspace/test_192.168.1.202_pipeline:/home/workspace1 --name test_192.168.1.202_pipeline_8 qnx:7.1
17:30:47  docker: 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.24/containers/create?name=test_192.168.1.202_pipeline_8": dial unix /var/run/docker.sock: connect: permission denied.
17:30:47  See 'docker run --help'.

docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run_第1张图片
原因分析:jenkins执行的用户没有docker权限
解决方法:(以下为root用户操作)
1.查看docker.sock 文件所属的用户组

ll /var/run/docker.sock 

2.检查 docker 用户组是否存在

cat /etc/group |grep docker

3.如果不存在用户组 docker,创建此用户组

groupadd docker

4.将所需用户添加到docker组

gpasswd -a 用户名 docker

5.更新用户组

newgrp docker

6.切换到普通用户,执行docker命令进行验证

docker images
docker ps -a

你可能感兴趣的:(docker,unix,容器)