错误:无法连接到[MASKED]处的Docker守护程序,Docker守护进程是否正在运行?

w1e3prcc  于 2023-06-05  发布在  Docker
关注(0)|答案(1)|浏览(127)

我已经为这个问题苦苦思索了好几个小时,但似乎找不到解决办法。我有一个自托管的gitlab-runner,它是一个Amazon Linux 2 EC2示例。我安装了git,docker和gitlab-runner(并成功注册)。下面是我的.gitlab-ci.yml文件:

- install
  - lint
  - build-nodejs-app
  - test
  - build-docker-image

install_dependencies:
  image: node:15.6.0-alpine
  stage: install
  script:
    - npm install

format:
  image: node:15.6.0-alpine
  stage: lint
  script:
    - npm install --global prettier
    - prettier --write .

lint:
  image: node:15.6.0-alpine
  stage: lint
  script:
    - npm run lint

build:
  image: node:15.6.0-alpine
  stage: build-nodejs-app
  script:
    - npm install
    - npm run build
  artifacts:
    paths:
      - build/

test_index_file:
  image: node:15.6.0-alpine
  stage: test
  script:
    - test -f build/index.html

unit_tests:
  image: node:15.6.0-alpine
  stage: test
  script:
    - npm install
    - npm run test

build-docker-image-aws:
  image: docker:stable
  services:
    - docker:dind
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_TLS_CERTDIR: ""
  stage: build-docker-image
  before_script:
    - mkdir -p ~/.aws
    - echo $AWS_ACCESS_KEY_ID > ~/.aws/credentials
    - echo $AWS_SECRET_ACCESS_KEY >> ~/.aws/credentials
  script:
    - docker info
    - docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
    - cp -R build/ app/
    - docker build -t $DOCKER_IMAGE_NAME .
    - docker push $DOCKER_IMAGE_NAME
    - docker run --rm -v ~/.aws:/root/.aws amazon/aws-cli ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --force-new-deployment
  dependencies:
    - build

尝试构建一个node.js应用程序,将工件推送到docker以构建镜像,然后使用Terraform部署到AWS(稍后我将集成Terraform部分)。在辛苦地为gitlab-ci文件获取正确的配置之后,这似乎是一堵我无法逾越的砖墙。
这是我得到的错误:

$ echo $AWS_ACCESS_KEY_ID > ~/.aws/credentials
$ echo $AWS_SECRET_ACCESS_KEY >> ~/.aws/credentials
$ docker info
Client:
 Debug Mode: false
Server:
ERROR: Cannot connect to the Docker daemon at [MASKED]. Is the docker daemon running?
errors pretty printing info
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

我已经将ec2-user和gitlab-runner添加到docker组中,并成功地在两者上运行了docker run hello-world
sudo service docker status说它正在运行,但sudo service --status-all给出以下输出:

● cfn-hup.service - SYSV: Runs user-specified actions when a
   Loaded: loaded (/etc/rc.d/init.d/cfn-hup; bad; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:systemd-sysv-generator(8)
netconsole module not loaded
Configured devices:
lo eth0
Currently active devices:
lo eth0 docker0

sudo systemctl status docker.socket也显示“active”。
这是我的/etc/gitlab-runner/config.toml

[[runners]]
  name = "My Runner"
  url = "https://gitlab.com/"
  id = 0
  token = REDACTED
  token_obtained_at = 0001-01-01T00:00:00Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "docker"
  [runners.cache]
    MaxUploadedArchiveSize = 0
  [runners.docker]
    tls_verify = false
    image = "ubuntu:latest"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock","/opt/gitlab-runner/cache:/cache:rw"]
    shm_size = 0

[[runners]]
  name = "Runner on AWS EC2"
  url = "https://gitlab.com/"

感觉我在绕圈子。我很感激任何建议。

pftdvrlh

pftdvrlh1#

我不确定这是唯一的/ root问题,但我想说,对于所有较新版本的Docker,您都希望使用TLS连接而不是禁用它。DIND docs有一些关于标志等的有用信息。
事实上,Gitlab CI FAQ将其列为该错误的原因。

相关问题