【问题标题】:Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running无法连接到 unix:///var/run/docker.sock 上的 Docker 守护程序。 docker 守护进程是否正在运行
【发布时间】:2019-03-25 21:06:33
【问题描述】:

我正在使用 gitlab ci 继续集成,我想对我的代码运行单元测试,然后构建一个 docker 映像,然后部署它。 但我面临的问题是如何在 gilab ci 中运行 docker 服务。

我收到这个错误

"Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running"

在我的 docker build 命令运行之后。 我需要在 gitlab-ci 中安装 docker 吗?

这是我的 .gitlab-ci.yml 文件

image: node:latest

before_script:

stages:
  - test
  - production
  - clean_up

services:
  - docker:dind

test:
  stage: test
  script:
    - npm install
    - npm install -g swagger
    - npm test

production:
  type: deploy
  stage: production
  image: docker:latest
  script:
    - docker build -t testimage -t testimage:latest .
    - docker tag testimage docker.abc.xyz.com/testimage
    - docker push docker.abc.xyz.com/testimage
  only:
    - development

clean_up_job:
  stage: clean_up
  script:
    - rm -rf node_modules
    - npm uninstall -g swagger
  when: on_failure

我目前没有使用 GitLab Runner。

【问题讨论】:

标签: docker gitlab-ci


【解决方案1】:

尝试将services 放入production 作业中,如下所示:

production:
  type: deploy
  stage: production
  image: docker:latest
  services:
    - docker:dind
  script:
    - docker build -t testimage -t testimage:latest .
    - docker tag testimage docker.abc.xyz.com/testimage
    - docker push docker.abc.xyz.com/testimage
  only:
    - development

【讨论】:

  • 解决方案的关键是我们需要docker:dind服务!
【解决方案2】:

尝试使用

  --docker-privileged \
  --docker-volumes /var/run/docker.sock:/var/run/docker.sock \
  --docker-volumes /home/gitlab-runner/docker-cache \

设置跑步者

您可以在设置跑步者的服务器上签入/etc/gitlab-runner/config.toml

【讨论】:

    猜你喜欢
    • 2017-11-24
    • 2022-07-07
    • 2020-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    相关资源
    最近更新 更多