尝试从Gitlab CI中的项目构建docker映像时收到错误

尝试从Gitlab CI中的项目构建docker映像时收到错误,docker,gitlab,gitlab-ci,gitlab-ci-runner,Docker,Gitlab,Gitlab Ci,Gitlab Ci Runner,我是Devops新手,我正在尝试在自托管gitlab实例中构建Docker映像。我已经从Docker image安装了Gitlab,从Docker image安装了Gitlab runner,我可以看到Gitlab内部的运行程序,我已经为某个项目配置了它,我创建了一个Gitlab-ci.yml文件,然后转到jobs,将项目构建为Docker映像。它说运行几秒钟之后,它会给我以下错误: ERROR: Failed to remove network for build ERROR: Prepara

我是Devops新手,我正在尝试在自托管gitlab实例中构建Docker映像。我已经从Docker image安装了Gitlab,从Docker image安装了Gitlab runner,我可以看到Gitlab内部的运行程序,我已经为某个项目配置了它,我创建了一个Gitlab-ci.yml文件,然后转到jobs,将项目构建为Docker映像。它说运行几秒钟之后,它会给我以下错误:

ERROR: Failed to remove network for build
ERROR: Preparation failed: Got permission denied while trying to connect to the Docker 
daemon socket at unix:///var/run/docker.sock: Get 
http://%2Fvar%2Frun%2Fdocker.sock/v1.25/info: dial unix /var/run/docker.sock: connect: 
permission denied (docker.go:858:0s)
我已尝试使用此命令授予权限的解决方案:

sudo chmod 666 /var/run/docker.sock
以下是gitlab-ci.yml文件内容:

# This file is a template, and might need editing before it works on 
your project.
# Build a Docker image with CI/CD and push to the GitLab registry.
# Docker-in-Docker documentation: 
https://docs.gitlab.com/ee/ci/docker/using_docker_build.html
#
# This template uses one generic job with conditional builds
# for the default branch and all other (MR) branches.
docker-build:
# Use the official docker image.
image: docker:latest
stage: build
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" 
$CI_REGISTRY
# Default branch leaves tag empty (= latest tag)
# All other branches are tagged with the escaped branch name (commit 
ref slug)
script:
- |
  if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
    tag=""
    echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 
'latest'"
  else
    tag=":$CI_COMMIT_REF_SLUG"
    echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
  fi
- docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" .
- docker push "$CI_REGISTRY_IMAGE${tag}"
# Run this job in a branch where a Dockerfile exists
rules:
- if: $CI_COMMIT_BRANCH
  exists:
    - Dockerfile
在那之后,我尝试构建这个项目,但是我得到了同样的错误


请提前帮助和感谢

您能出示您的.gitlab-ci.yml吗?或者也许我用文件中添加的内容部分修改了问题