背景
在我的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
。如您所见,我正在尝试:
错误
但是,我收到以下错误:
$ 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/