Flame_Phoenix
Flame_Phoenix

Reputation: 17564

docker: command not found in gitlab-ci

Background

in my gitlab-ci file I am trying to build a docker image, however even though I have docker:dind as a service, it is failing.

.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

The problematic stage is docker. As you can see I am trying to:

  1. login into docker
  2. build an image from gitlab's registry
  3. push that image

Error

However, I am getting the following error:

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

Which is confusing, because docker:dind is supposed to actually prevent this from happening:

https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#enable-registry-mirror-for-dockerdind-service

Question

So clearly I am missing something here. What am I doing wrong?

EDIT

This is my 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"]

Upvotes: 1

Views: 5799

Answers (1)

erik258
erik258

Reputation: 16275

image is used to specify the image in which to run the script. You want to run the script in a docker image, to build your image.

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

After all, isn't your application image CI_REGISTRY_IMAGE in this? You don't want to build the image in itself.

    - docker build . -t ${CI_REGISTRY_IMAGE}:latest
    - docker push ${CI_REGISTRY_IMAGE}:latest

Upvotes: 2

Related Questions