Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
manfon10 opened this issue Aug 27, 2023 · 2 comments
Assignees
Labels
help wanted Extra attention is needed Kubernetes

Comments

@manfon10
Copy link

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
Copy link
Owner

jforge commented Aug 28, 2023

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
Copy link
Owner

jforge commented Aug 28, 2023

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:

  • disabling the --init and --privileged options, set both DIND and TINI_SUBREAPER to false
  • added the docker dind sidecar container and configured the DOCKER_HOST setting for the agent container configuration

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: {}

@jforge jforge self-assigned this Aug 28, 2023
@jforge jforge added help wanted Extra attention is needed Kubernetes labels Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed Kubernetes
Projects
None yet
Development

No branches or pull requests

2 participants