在 Jenkinsfile 中,我尝试下载 docker 镜像并在此 docker 镜像中使用所有 git pull 和前端构建内容。
我的 jenkinsfile 到此为止:
pipeline {
agent any
stages {
stage('Install Docker-CE') {
steps {
sh '''curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce'''
}
}
stage('Start Docker') {
steps {
sh 'sudo service docker start'
sh 'sudo service docker status'
}
}
stage('Verify Docker') {
steps {
sh 'sudo docker run hello-world'
}
}
stage('Build Back End') {
steps {
git ([url : 'https://github....git', branch : 'develop', credentialsId : 'xxx' ])
}
}
}
docker 已安装并正在运行,因为在我运行 sudo service docker status 的“启动 Docker”步骤中,它显示:Docker 正在运行
但是在下一步中尝试执行“hello world”时,它显示 docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
我还尝试使用以下命令运行 docker 守护进程:sudo dockerd
但它没有帮助,这是输出的一部分:
time="2021-07-28T08:45:04.782471391Z" level=error msg="failed to mount overlay: permission denied" storage-driver=overlay2
time="2021-07-28T08:45:04.782647045Z" level=error msg="exec: \"fuse-overlayfs\": executable file not found in $PATH" storage-driver=fuse-overlayfs
time="2021-07-28T08:45:04.783389746Z" level=warning msg="[graphdriver] WARNING: the aufs storage-driver is deprecated, and will be removed in a future release"
time="2021-07-28T08:45:04.810999832Z" level=warning msg="Your kernel does not support CPU realtime scheduler"
time="2021-07-28T08:45:04.811283522Z" level=info msg="Loading containers: start."
time="2021-07-28T08:45:04.816297382Z" level=warning msg="Running iptables --wait -t nat -L -n failed with message: `iptables v1.6.0: can't initialize iptables table `nat': Permission denied (you must be root)\nPerhaps iptables or your kernel needs to be upgraded.`, error: exit status 3"
time="2021-07-28T08:45:04.887136525Z" level=info msg="stopping event stream following graceful shutdown" error="<nil>" module=libcontainerd namespace=moby
time="2021-07-28T08:45:04.887859247Z" level=info msg="stopping event stream following graceful shutdown" error="context canceled" module=libcontainerd namespace=plugins.moby
time="2021-07-28T08:45:04.887889167Z" level=info msg="stopping healthcheck following graceful shutdown" module=libcontainerd
failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables -t nat -N DOCKER: iptables v1.6.0: can't initialize iptables table `nat': Permission denied (you must be root)
Perhaps iptables or your kernel needs to be upgraded.
(exit status 3)
答案 0 :(得分:0)
好的,问题是我在 sudo
中使用了 sudo docker run hello-world
。没有 sudo
它可以工作...