CICD
[Jenkins] Docker Build Error: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
chul542
2022. 2. 10. 15:38
Jenkin에서 Docker plugin을 제공해 주지만 Execute Shell에서 docker build 명령어로 직접 빌드 하려면 Jenkins Docker image 안에 Docker를 설치 해야 하고 Docker image 안에서 Docker를 빌드하면 다음과 같은 에러가 난다.
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
저 에러를 구글에서 검색하면 docker 서비스를 재사작 하라고 한다.
Docker 재시작
systemctl start docker
이 명령어를 치면
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
다음과 같은 에러가 나온다. Docker image 안에서 Docker 띄우는 것은 불가능 하게 막아 놓은 것 같다.
해결책
docker.sock 파일과 docker client를 Jenkins Docker image가 띄워져 있는 host 컴퓨터와 공유 하면 된다.
-v /var/run/docker.sock:/var/run/docker.sock
-v /usr/bin/docker:/usr/bin/docker
# 최종 Docker Run 명령어
docker run -d --restart always --name jenkins --user root \
-p 8080:8080 -v /home/wapl/jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker \
-v /root/.docker:/root/.docker jenkins/jenkins