-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[Discussion] Getting jenkins
communication issue with docker daemon
#13
Comments
While during my investigation, I created a pipeline, but refused to build due to a failure. Here is my below pipeline script
Build error as
|
hi @devopsjourney1! It's been quite a while now. Maybe you were busy with ur works. Could take a look here and help me debug this issue? TYIA! |
run
and attach the output |
hey @RogerTaylor130 here what I found
|
Hi, @afzal442 Can you post all the Jenkins logs since you got You need to know,
|
To make it simpler, plz consider this pipeline
LMK if u r able to run the abv pipeline. I have Below is the full logs
Plz suggest how to debug this. Thanks |
Well. The pipeline looks fine to me but I did not test it. Looks like your pipeline is running on the Try to run |
Thanks for quick response.
Sorry! How? But if I ran |
SSH into your Jenkins machine and run
|
I am just looping around;
Here you go, I hope you have read the comment abv. Thanks
|
Not sure about the k8s installation. Just let u know your pipeline is called the |
Ah I see. I don't think Edit: What would u say abt it https://www.jenkins.io/doc/book/pipeline/docker/ ? |
I am not sure how far you have gone with docker, k8s, jenkins... But jenkins does not have very close connection with docker and k8s. I suggest go with jenkins and docker first then k8s. Study a little bit deep since you don't know about some basic concepts of jenkins like node/agent... Well... I am not good as well so it's just my personal advice. Good lucky. |
@afzal442 If you need docker in your K8's pod you will either have to run the pod with elevated privileges AND pass in the host machine's docker socket. OR You can install docker inside your container, which can be very challenging to do but is the better approach from a security perspective. What you are going to have to do is create a customer jenkins docker container image that has the docker daemon installed. Once that is done you can look up instructions for creating on demand jenkins nodes/agents/runners using Kubernetes. |
Thanks @RogerTaylor130 for digging into it alongside me. I am flattered by your quick responses and suggestions. Again for your advice. 😄 |
Hi @shadycuz ! I am glad you came into this discussion. Your suggestions/approaches look promising to me. I can't thank you enough. I will try those approaches whichever work for me. And try to sync with you. Thanks. |
Hi @shadycuz ! I tried to figure out on how to run the pod with elevated privileges AND pass in the host machine's docker socket. Any clue! My installations follows this https://www.jenkins.io/doc/book/installing/kubernetes/#install-jenkins-with-yaml-files One quick question how do you run this below pipeline after installing JenkinsCI
Does that work for you? This says What possibly I could try after installing? Thanks! |
@afzal442 I worked on it this weekend. It's very hard. I have done it a number of different ways and its always a pain. If you just wanted to build a docker image and push then its very easy. But what you want to do happens to be extremely hard. Usually I run production Jenkins outside of container and develop my pipelines on container Jenkins. But what you want to do is completely reasonable... it's just very difficult to implement. I have made my own community post about this here. |
Thanks much Levi getting around that and supporting me on the fly! BTW, It's been pain for me as well. 😖
Absolutely. So do I.
Do you mean Docker container here? If so, I can understand.
So what did I next is I tried to create agent
So glad to know that. Let me know when have any update. 😄 |
Yeah that is easy to do. But the pipeline you show above:
This actually involves sending the build workspace into the Docker container and this will not work very easily if the workspace is already inside of a container.
Yes, usually I run the Jenkins agents on bare VM's. This means I don't have any docker in docker issues.
The guide you linked is a generic guide about creating a single agent. You need a guide for creating Jenkins agents on Kubernetes. You need to configure this plugin. This will involve some extra work, like making sure you Jenkins Controller as access to the Kubernetes API via a Service Account. It's worth it to understand and have dynamic agents configured first and then move on to Docker. But like I said earlier, you will only be able to build and push docker images if the agent running the pipeline is inside of a container. |
Yes! that's perfect. I will come to that once I get rid of that part of docker socket issue. Actually, I wanted to remove the barrier b/w
Got that. That means in my case the agent running the pipeline is outside of a container becaz of not having my Docker socket connection. Right?
Sorry if you can be explicit here a bit more. Thanks |
Are you doing this for fun? Or for production? Because if you are doing this for fun you can skip the agent thing for now.
You need to have the agents running first. Once the agents are working, then you can try and figure out how to get docker working on them. Remember you have 3 options for getting docker running
Also... The first option might not even be possible depending on how you run your K8 cluster. For example if you are using digital ocean then you dont get access to the k8 workers, you can't install docker on the host to pass it to pods anyways. You might also run into challenges with the second option. You might want to run an existing Jenkins agent container without modifying it. That leaves the third option which is what other CICD services like circleci and gitlab are using.
You will still be able to run Jenkins Pipelines, you just wont be able to run on docker agents. You will still be able to build and push docker images if you wanted.
When you try to run on a docker agent like this:
Jenkins takes the current workspace and trys to bind mount it inside the container. So if the Jenkins agent that is running the pipeline, is also in a container then it wont work. The workspace will be empty instead of having anyfiles or anything you might want to checkout. To be fair, this might work for the simple pipeline example you gave but if you have a more realistic pipeline like... node('dynamic-k8-pod') {
checkout('my-python-app')
docker.image('python-black:latest').inside {
stage('Format Code') {
sh('black --some args')
}
}
docker.image('python-lint:latest').inside {
stage('Lint Code') {
sh('pylint--some args')
}
}
} This pipeline ^ would not work correctly if the agent running the job is already in a container. |
Thanks again. Now it gives much more sense. I am using In order to run that pipeline, you mentioned abv I have to create Docker node agent to establish a connection b/w the Jenkins controller and container agent to build the workspace. Right? When we say outside of a container, it means |
@afzal442 You will need to use the Kubernetes plugin to spin up dynamic Jenkins agents on demand. Those agents will run in their own pod and that pod needs a docker sidecar container to provide the remote docker daemon. You can use this guide as a reference, just replace spacelift with Jenkins agent. |
hmm! That will be a nice extensible work. I will try on top of k8s plugin and see if it works for me. Thanks. 😄 |
Hi @devopsjourney1! I have hard finding about setting up
jenkins
pipeline with docker agent. Since I have followed these steps from the docs here, but when I try to follow the steps from ur video, I am failing to create a labeldocker
agent.Is it necessary to install jenkins through
docker
to establish connection b/w docker host and jenkins server?When I skip the docker installation as I have done through kubernetes and follow the docker socket connection like this
docker network create jenkins
anddocker run -d --restart=always -p 127.0.0.1:2376:2375 --network jenkins -v /var/run/docker.sock:/var/run/docker.sock alpine/socat tcp-listen:2375,fork,reuseaddr unix-connect:/var/run/docker.sock
, I still fail to make the connection successful. Any thoughts here plz?The text was updated successfully, but these errors were encountered: