尝试使用unix:///var/run/docker.sock

时间:2019-12-30 10:21:34

标签: docker jenkins docker-compose

我想在我的vps上安装一些dockerized工具。其中包括詹金斯和一个代理。一切都很好,但是在詹金斯中使用Docker代理时,我遇到了这个错误:

+ docker build -t 286802dd81862d714cfc6a90c84d30200546eaa9 -f Dockerfile .

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.39/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&rm=1&session=srtihghhshf8z9c2lkdnvr8dm&shmsize=0&t=286802dd81862d714cfc6a90c84d30200546eaa9&target=&ulimits=null&version=1: dial unix /var/run/docker.sock: connect: permission denied

script returned exit code 1

这是我的docker-compose的样子:


services:

  proxy:
    image: jwilder/nginx-proxy
    networks:
      - mynetwork
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
    restart: always

  mariadb:
    image: bitnami/mariadb:latest
    ...

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    ...

  jenkins:
    image: jenkinsci/blueocean:latest
    networks:
      - mynetwork
    environment:
      - VIRTUAL_HOST=jenkins.mydomain.com
      - VIRTUAL_PORT=8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./jenkins-data:/var/jenkins_home
      - ./jenkins-docker-certs:/certs/client:ro
      - ./jenkins-home:/home
    restart: always

networks:
  mynetwork:
    driver: bridge

我在撰写文件中缺少什么吗?

到目前为止,我已经尝试将jenkins用户添加到正在运行的docker实例上的docker和root组中,但是没有成功。

1 个答案:

答案 0 :(得分:0)

我找到了解决此问题的方法。我只是像这样在docker-compose.yml中指定了root用户:

  jenkins:
    image: jenkinsci/blueocean:latest
    user: root
    networks:
      - mynetwork
    environment:
      - VIRTUAL_HOST=jenkins.mydomain.com
      - VIRTUAL_PORT=8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./jenkins-data:/var/jenkins_home
      - ./jenkins-docker-certs:/certs/client:ro
      - ./jenkins-home:/home
    restart: always