jforge / docker-jenkins-inbound-agent

jenkins-inbound-agent enhanced for docker and docker-compose support
MIT License
1 stars 2 forks source link

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? #2

Open manfon10 opened 1 year ago

manfon10 commented 1 year ago

Hi, I am using your image to use jenkins-agent with docker, but when I run commands I get the error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? Do you know what it could be?

I'm using a kubernetes POD, thanks.

jforge commented 1 year ago

Hi Manuel.

docker: Cannot connect to the Docker daemon at unix:///Users/cybus-pi/.docker/run/docker.sock. Is the docker daemon running?. normally means, that your docker daemon is not running. You need to ensure this with the settings you see.

This project was used within docker environments and I never used it in a K8s environment.

From my understanding you might need to provide a sidecar container to use the Docker plug-in in pipelines, see for example https://applatix.com/case-docker-docker-kubernetes-part-2/

Never tried out, but I'm interested in your results. Maybe to want to contribute a PR here with your final K8s solution?

jforge commented 1 year ago

Follow-up.

To make it work you should follow the docker-in-docker guide for Kubernetes I mentioned (https://applatix.com/case-docker-docker-kubernetes-part-2/) It's about finding the route to a reachable DOCKER_HOST and configuring it properly.

Limitations

As I'm current not using this on K8s I cannot assure that every works, especially with regard to proper subreaper settings (might be something for the k8s init containers) and the privileged mode (which should normally NOT be required on K8s). I tested on a Jenkins pipeline with using the docker plugin, which successful downloads an image to the agent container and started a container, but I'm currently not completely aware of potential issues with the processes and signal handling, please try this out and let me know, what you find.

How to resolve

I've created a simple k8s deployment and skipped all options not applicable for the K8s environment:

After that you can open a shell in the deployed agent container and see success with docker run -it --rm node:lts-alpine node --version

So that I consider this ticket is resolved, do you agree?

The K8s resource I used looks like this:

## How to use:
## - Install:
##   kubectl create namespace jenkins-agents
##   kubectl -n jenkins-agents create -f ./jenkins-agent-deployment.yaml
## - Delete:
##   kubectl -n jenkins-agents delete deployment jenkins-inbound-agent
## - Look at logs:
##   kubectl -n jenkins-agents logs -flapp=jenkins-inbound-agent
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: jenkins-inbound-agent
spec:
  selector:
    matchLabels:
      app: jenkins-inbound-agent
  replicas: 1
  template:
    metadata:
      labels:
        app: jenkins-inbound-agent
    spec:
      containers:
        - name: jenkins-inbound-agent
          image: jforge/jenkins-inbound-agent:additional-tools
          env:
            - name: JENKINS_URL
              value: "https://<your-jenkins-controller-host>"
            - name: JENKINS_WEB_SOCKET
              value: "true"
            - name: JENKINS_SECRET
              value: "ve|2yv3rys3cr3t"
            - name: JENKINS_AGENT_NAME
              value: "K8s-Agent"
            - name: DIND
              value: "false"
            - name: TINI_SUBREAPER
              value: "false"
            - name: DOCKER_HOST
              value: tcp://localhost:2375
          resources:
            requests:
              cpu: 800m
              memory: 500Mi
        - name: dind-daemon
          image: docker:1.12.6-dind
          resources:
            requests:
              cpu: 20m
              memory: 512Mi
          securityContext:
            privileged: true
          volumeMounts:
            - name: docker-graph-storage
              mountPath: /var/lib/docker
      volumes:
        - name: docker-graph-storage
          emptyDir: {}