Jenkins Docker Container cannot access docker.sock

I deployed a standard Jenkins Docker image using docker-compose and this configuration:

deployer:
  image: jenkins
  volumes:
    - "/mnt/jenkins:/var/jenkins_home"
    - "/var/run/docker.sock:/var/run/docker.sock"
  ports:
    - "2375:2375"
    - "8080:8080"
    - "50000:50000"

After reading the many SO questions I tested, Root was added to the docker user group with help gpasswd -a ${USER} dockerand confirmed that the user inside the container is root c docker exec jenkins_deployer echo ${USER}.

When I try to add Docker access to the Jenkins user interface using "Docker URL = unix: ///var/run/docker.sock", I get the error message " org.newsclub.net.unix.AFUNIXSocketException: Permission denied (socket : /run/docker.sock) "

How can I give Jenkins access to docker.sock to automatically deploy Docker containers?

+5
1

, , , .

Jenkins, Docker. , :

Dockerfile

FROM jenkins/jenkins:latest

USER root
RUN apt-get update -qq \
    && apt-get install -qqy apt-transport-https ca-certificates curl gnupg2 software-properties-common
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN add-apt-repository \
  "deb [arch=amd64] https://download.docker.com/linux/debian \
  $(lsb_release -cs) \
  stable"
RUN apt-get update  -qq \
    && apt-get install docker-ce=17.12.1~ce-0~debian -y

RUN usermod -aG docker jenkins

-compose.yml

version: '3'

services:
  jenkins:
    container_name: 'jenkins-container'
    privileged: true
    build: .
    ports:
      - '8080:8080'
      - '50000:50000'
    volumes:
      - jenkins-data:/var/jenkins_home
    restart: unless-stopped

volumes:
  jenkins-data:

:

docker-compose up

, Docker :

docker exec -it --user root <CONTAINER_ID>

service docker start

! , .

<YOUR_IP>:8080 , Jenkins, Docker Containers.

0

Source: https://habr.com/ru/post/1667887/


All Articles