docker - docker:在gitlab-ci中找不到命令

标签 docker gitlab gitlab-ci

背景
在我的gitlab-ci文件中,我正在尝试构建docker镜像,但是,即使我将docker:dind作为服务,它仍会失败。.gitlab-ci

---
stages:
  - build
  - docker

build:
  stage: build
  image: fl4m3ph03n1x/my-app:1.0
  variables:
    MIX_ENV: prod
  script:
    - mix deps.get
    - mix deps.compile
    - mix compile
  artifacts:
    paths:
      - .hex/
      - _build/
      - deps/
      - mix.lock

build_image:
  stage: docker
  image: fl4m3ph03n1x/my-app:1.0
  variables:
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
    DOCKER_HOST: tcp://docker:2375/
  services:
    - docker:dind
  script:
    - echo ${CI_JOB_TOKEN} | docker login --password-stdin -u ${CI_REGISTRY_USER} ${CI_REGISTRY}
    - docker build . -t ${CI_REGISTRY_IMAGE}:latest
    - docker push ${CI_REGISTRY_IMAGE}:latest
有问题的阶段是docker
如您所见,我正在尝试:
  • 登录到docker
  • 从gitlab的注册表
  • 构建镜像
  • 推送该图像

  • 错误
    但是,我收到以下错误:

    $ echo ${CI_JOB_TOKEN} | docker login --password-stdin -u ${CI_REGISTRY_USER} ${CI_REGISTRY} /bin/bash: line 110: docker: command not found


    这令人困惑,因为docker:dind应该实际上阻止了这种情况的发生:
    https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#enable-registry-mirror-for-dockerdind-service

    很明显,我在这里缺少任何东西。我究竟做错了什么?
    编辑
    这是我的Dockerfile
    FROM elixir:1.10
    
    # Install Hex + Rebar
    RUN mix do local.hex --force, local.rebar --force
    
    COPY . /
    WORKDIR /
    
    ENV MIX_ENV=prod
    RUN mix do deps.get --only $MIX_ENV, deps.compile
    RUN mix release
    
    EXPOSE 8080
    ENV PORT=8080
    ENV SHELL=/bin/bash
    
    CMD ["_build/prod/rel/my_app/bin/my_app", "start"]
    

    最佳答案

    image用于指定运行脚本的图像。您要在docker图像中运行脚本以构建图像。

    The image keyword is the name of the Docker image the Docker executor runs to perform the CI tasks.


    https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#define-image-and-services-from-gitlab-ciyml
    毕竟,这不是您的应用程序镜像CI_REGISTRY_IMAGE吗?您不想自己构建图像。
        - docker build . -t ${CI_REGISTRY_IMAGE}:latest
        - docker push ${CI_REGISTRY_IMAGE}:latest
    

    关于docker - docker:在gitlab-ci中找不到命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64667460/

    相关文章:

    caching - gitlab-ci runners 中具有不同到期时间的多条路径

    docker - 如何在 Docker 构建期间强制构建 arg?

    docker - 如何使用 .env 文件中的环境变量填写同一个 .env 文件中的其他环境变量

    docker - 无权推送到 GCR - 但我是该项目的所有者

    api - 亚搏体育appGitLab API :How to get branches order by commit_time

    python - Pytest 未从目录中选择所有测试

    sbt - 在 gitlab ci 中运行 sbt 测试

    c# - API 不起作用,使用 Docker 和 ASP.NET CORE

    git - 如何将包含大量项目和公共(public)库的SVN存储库迁移到Git/Gitlab?

    gitlab - 安装 charlock_holmes 时出错 : Error installing GITLAB