m getting the docker daemon issue ,dial unix /var/run/docker.sock: connect: permission denied
Update docker file
FROM jenkins/jenkins:lts-jdk11
LABEL maintainer ashish<[email protected]>
USER root
RUN apt-get update &&
apt-get install sudo &&
yes |apt-get install vim
# system preparation
RUN sudo apt-get -y install apt-transport-https ca-certificates software-properties-common curl
RUN sudo apt-get update && apt-get install -y apt-transport-https
# Install Docker client
ENV DOCKER_BUCKET download.docker.com
ENV DOCKER_VERSION 19.03.8
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
RUN apt-get update
RUN apt-get -y install docker-ce
RUN docker -v
RUN sudo /etc/init.d/docker start
# RUN sudo systemctl enable docker
# kubectl
COPY kubectl ./kubectl
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
RUN chmod +x kubectl
&& mv ./kubectl /usr/local/bin/kubectl
ENV PATH="${PATH}:/usr/local/bin/docker"
RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers
#Switch user to jenkins
# USER jenkins
inside the container i cann see docker -v
but docker ps is not working.
is there any docker client also i need to download,which will run my docker-daemon
2
Answers
I would suggest you to use a custom docker image in your deployment which will consist both Jenkins and Docker therefore should resolve your problem. You will need to have docker in your Mac First.
Dockerfile
This will build your image on your machine with both Jenkins and Docker inside it. You can verify the image using the following command:
Replace your image in
Deployment
with your custom image.For more understanding of this use case then check this link out.
I think the issue comes from the fact that when it works on your local dev machine, you had used
--priviledged
.In you deployment manifest you set hostPath to the worker node docker socket which is right, BUT neither the pod securityContext does not grant any elevated access to the mountPath, nor the container securityContext not allowing privilege escalation.
There is no way this can work unless you allow more elevated priviledges either at the pod level or at the container level security contexts.