Gitlab作业失败-找不到Docker命令

时间:2019-07-04 09:49:42

标签: docker gitlab

当我尝试在gitlab管道上运行deploy作业时,出现以下错误;

$ docker login -u gitlab-ci-token -p "$CI_BUILD_TOKEN" "$CI_REGISTRY"
/bin/bash: line 84: docker: command not found

我的gitlab-ci.yml看起来像这样

image: docker:latest

services:
  - docker:dind

before_script:
  - docker login -u gitlab-ci-token -p "$CI_BUILD_TOKEN" "$CI_REGISTRY"

stages:
  - lint
  - test
  - build
  - build-image
  - deploy

deploy:
  stage: deploy
  image: registry.gitlab.com/username/someimage:latest
  script: 
    - some deploy command
  only:
    refs:
      - master
      - develop
      - staging

2 个答案:

答案 0 :(得分:1)

docker login中的

before_script是根据您指定的私有映像在容器中执行的:registry.gitlab.com/username/someimage:latest

该图像未安装docker,因此出现错误消息。

根据您的情况,您可以:

  • 在该映像中安装docker(无论您在何处创建)
  • 或者如果它是基于Ubuntu的,则在GitLab作业中直接作为第一行apt-get update && apt-get install docker.io
  • 或使用完全已经具有docker的另一个图像

这实际上取决于最终要实现的目标。

答案 1 :(得分:0)

image: docker:git

services:
  - docker:dind

before_script:
  - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com

stages:
  - lint
  - test
  - build
  - build-image
  - deploy

deploy:
  stage: deploy
  image: registry.gitlab.com/username/someimage:latest
  script: 
    - apt update
    - ...
  only:
    refs:
      - master
      - develop
      - staging
相关问题