简体   繁体   中英

How to mount /var/run/docker.sock usr/bin/docker to docker container using docker-compose?

I want to bind my docker binaries and docker.sock to my docker jenkins container so that i will be able to use docker inside jenkins. This is my docker-compose.yml

version: "2"

services:
  traefik:
    image: traefik
    restart: always
    container_name: "${PROJECT_NAME}_traefik"
    command: --api --docker
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - ./traefik.toml:/traefik.toml
      - ./acme.json:/acme.json
    labels:
      - "traefik.frontend.rule=Host:${PROJECT_BASE_URL}"

  jenkins:
    #image: jenkins/jenkins
    build: .
    container_name: "${PROJECT_NAME}_jenkins"
    environment:
      - "JAVA_OPTS=-Dmail.smtp.starttls.enable=true"
    ports:
      - '50000:50000'
    volumes:
      - ./jenkins_home:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker
    labels:
      - "traefik.frontend.rule=Host:${PROJECT_BASE_URL}"

Is there something I missed? I am not using sudo when running docker-compose start.

You need to make the jenkins container privileged to access a device. By default this is turned off, probably for security.

See https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities for more details, it even gives the example of running the docker daemon.

In your docker compose file add privileged: true to your jenkins service

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM