加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

无法在unix:///var/run/docker.sock连接到Docker守护程序. dock

发布时间:2020-12-16 03:35:56 所属栏目:安全 来源:网络整理
导读:我正在使用gitlab ci进行持续集成,我想对我的代码运行单元测试,然后构建一个docker镜像然后进行部署. 但我面临的问题是如何在gilab ci中运行docker服务. 我收到这个错误 "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docke

我正在使用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.

最佳答案
尝试将服务放在生产作业中,如下所示:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读