/bin/bash: line 89: docker: command not found

hello, I am trying to push my code on Gitlab but it constantly fails on the push stage giving me the below error. I would really appreciate any suggestions of how to tackle this issue…

1 Running with gitlab-runner 12.6.0-rc1 (ec299e72)
2   on docker-auto-scale 72989761
3
Using Docker executor with image ruby:2.5 ...
00:33
4 Pulling docker image ruby:2.5 ...
5 Using docker image sha256:54cb86b0bcdc353e103e9dd1bff69fcd01e3235420ed17cbf5efac22010b373e for ruby:2.5 ...
7
Running on runner-72989761-project-16129735-concurrent-0 via runner-72989761-srm-1578007908-e356a4c4...
00:05
9
$ eval "$CI_PRE_CLONE_SCRIPT"
00:01
10 Fetching changes with git depth set to 50...
12 Created fresh repository.
14  * [new ref]         refs/pipelines/106725538 -> refs/pipelines/106725538
15  * [new branch]      master                   -> origin/master
16 Checking out 4620472d as master...
17 Skipping Git submodules setup
21
$ docker login -u "gitlab-ci-token" -p "$CI_BUILD_TOKEN" "$CI_REGISTRY"
00:01
22 /bin/bash: line 89: docker: command not found
26 ERROR: Job failed: exit code 1

Hi,

please post the CI config here, the linked repo is private.
I assume you want to build a Docker image and push it to the registry?

Cheers,
Michael

hello Michael, thank you for your reply.
Please let me know what you think the issue could be, I’m only a beginner, so I’m not sure what may be causing it and I spent a lot of time researching this but no luck (I kept creating and deleting projects to see if sth could work).

current issue in the Push stage:

    1 Running with gitlab-runner 12.6.0-rc1 (ec299e72)
    2   on docker-auto-scale 72989761
    3
    Using Docker executor with image ruby:2.5 ...
    00:37
    4 Pulling docker image ruby:2.5 ...
    5 Using docker image sha256:54cb86b0bcdc353e103e9dd1bff69fcd01e3235420ed17cbf5efac22010b373e for ruby:2.5 ...
    7
    Running on runner-72989761-project-16138356-concurrent-0 via runner-72989761-srm-1578057356-89d9bc73...
    00:05
    9
    $ eval "$CI_PRE_CLONE_SCRIPT"
    00:02
    10 Fetching changes with git depth set to 50...
    11 Initialized empty Git repository in 
    12 Created fresh repository.
    13 From 
    14  * [new ref]         refs/pipelines/106836401 -> refs/pipelines/106836401
    15  * [new branch]      master                   -> origin/master
    16 Checking out 58e0d93f as master...
    17 Skipping Git submodules setup
    21
    $ docker login -u "gitlab-ci-token" -p "$CI_BUILD_TOKEN" "$CI_REGISTRY"
    00:01
    22 /bin/bash: line 89: docker: command not found
    26 ERROR: Job failed: exit code 1

my .gitlab.ci-yml file is as follows:

    stages:
  - pull
  - build
  - lint
  - push
  - deploy
  - cleanup

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

pull:
  stage: pull
  allow_failure: true
  script:
    - docker pull "$CI_REGISTRY_IMAGE":latest

build:
  stage: build
  script:
    - docker build --tag="$CI_PIPELINE_ID":"$CI_COMMIT_REF_NAME" --cache-from="$CI_REGISTRY_IMAGE":latest .

lint:
  stage: lint
  script:
    - echo $CI_COMMIT_REF_NAME
    - echo $CI_PIPELINE_ID
    - echo $CI_REGISTRY_IMAGE
    - export CI_PIPELINE_ID=$CI_PIPELINE_ID
    - export CI_BUILD_REF_NAME=$CI_COMMIT_REF_NAME
    - docker-compose -p "$CI_PIPELINE_ID" -f docker-compose.ci.yml run app flake8 .

push image:
  stage: push
  only:
    - master
    - tags
  script:
    - docker tag "$CI_PIPELINE_ID":"$CI_COMMIT_REF_NAME" "$CI_REGISTRY_IMAGE":"$CI_COMMIT_REF_NAME"
    - docker push "$CI_REGISTRY_IMAGE":"$CI_COMMIT_REF_NAME"

push latest:
  stage: push
  script:
    - docker tag "$CI_PIPELINE_ID":"$CI_COMMIT_REF_NAME" "$CI_REGISTRY_IMAGE":latest
    - docker push "$CI_REGISTRY_IMAGE":latest

cleanup:
  stage: cleanup
  when: always
  script:
    - docker rmi -f "$CI_PIPELINE_ID":"$CI_COMMIT_REF_NAME"
    - docker-compose -p "$CI_PIPELINE_ID" -f docker-compose.ci.yml down --remove-orphans

deploy:
  stage: deploy
  when: manual
  only:
    - master
  script:
    - docker-compose -f docker-compose.deploy.yml pull
    - docker-compose -f docker-compose.deploy.yml down --remove-orphans
    - docker-compose -f docker-compose.deploy.yml up -d

my docker-compose-deploy:

    version: '3'
services:

  backend:
    image: registry.gitlab.com/monixm/last-propulsion-project:latest
    restart: always
    networks:
      - nginx_network
      - database1_network  # <-- connect to the bridge
    env_file:
      - prod.env
    command: 'sh /scripts/run.sh'
    volumes:
      - frontend:/frontend-build
      - static-files:/static-files
      - media-files:/media-files
    depends_on:
      - database

  database:
    image: postgres:latest
    restart: always
    env_file:
      - prod.env
    volumes:
      - database:/var/lib/postgresql/data
    networks:
      - database1_network

  nginx:
    image: nginx:latest
    volumes:
      - static-files:/static-files
      - media-files:/media-files
      - ./config:/etc/nginx/conf.d
      - frontend:/frontend
      - /etc/letsencrypt:/etc/letsencrypt
    ports:
      - "80:80"
      - "443:443"
    command: /bin/bash -c "nginx -g 'daemon off;'"
    depends_on:
      - backend
    networks:
      - nginx_network

networks:  # <-- and here
  nginx_network:
    driver: bridge
  database1_network:  # <-- add the bridge
    driver: bridge

volumes:
  frontend:
  database:
  static-files:
  media-files:

my docker-compose:

    version: '3'
services:
  database:
    image: postgres:latest
    ports:
      - '5432:5432'
    env_file:
      - dev.env
    volumes:
      - database:/var/lib/postgresql/data

  app:
    image: registry.gitlab.com/monixm/last-propulsion-project:latest
    restart: always
    env_file:
      - dev.env
    command: '/usr/sbin/sshd -D'
    ports:
      - '8003:8000'
      - '4777:22'
    depends_on:
      - database
    volumes:
      - ./frontend:/frontend
      - ./backend:/backend
      - ./media-files:/media-files
      - ./static-files:/static-files
      - ./scripts:/scripts

volumes:
  database:

Hi,

did you build that setup yourself, or where did you copy the parts? From a first peek, it looks like as if the GitLab runner is configured to use the ruby image as default, and none of .gitlab-ci.yml references a different Docker image.

Using Docker executor with image ruby:2.5 ...

This works fine up until you’re calling the build job - which calls the docker CLI command but Docker isn’t installed inside the container.

Funnily enough the push image job works, but push latest fails.

Can you modify the before_script section and add a docker info execution? Possibly you are running into a different error here with Docker.

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

Cheers,
Michael

I built the project with my team mates - it was a final project for a course I attended and it worked just fine but then I wanted to launch it on my own domain & in my private Gitlab (not the school dedicated one) and ever since then I have had this problem. I have just updated default.conf file with my domain and the pipeline broke on the lint stage with the same ‘docker: command not found’ error…

Ok, I managed to solve this issue - it was caused by the fact that the shared runners were activated (hence gitlab was using ruby instead of shell executor which I chose initially when setting up gitlab runners). uff… thank you so much for your willingness to help, Michael, I appreciate it.

Ah. Shell executor. Now that makes sense, it would have been my next guess that the runner setup now differs :slight_smile: Glad you’ve solved it yourself, nifty CI pipeline overall :slight_smile:

Can you tell me how did you solve it, I am having same issue

Hello, in my case, I went to my project Settings on Gitlab - CI/CD - Runners - deactivate Shared Runners. This solved the issue. I hope it fixes it for you too.

Hi, I am also new to this. And if I disable shared runner then it mentions that no runner found.
My code:

gitlab stages

docker-test:
  stage: docker-test
  script: docker info    # working fine


integration-test:
  image: gradle:alpine
  stage: integration-test
  script:
    - gradle itest --info   # not working

build.gradle code :

task setupTestDB(type :Exec){
    commandLine 'sh','./src/integration/scripts/testDBSetup.sh'
}

task itest(type: Test, dependsOn: "test") {
    description = 'Runs the integration tests.'
    dependsOn setupTestDB
    useTestNG()
    mustRunAfter test
}

testDBSetup.sh :

docker run --rm --name pg_test -d -p 5100:5432 -e POSTGRES_USER=pg -e POSTGRES_PASSWORD=aaaaaa -e POSTGRES_DB=db_test postgres:9.6

And I get the error

Task :setupTestDB FAILED
./src/integration/scripts/testDBSetup.sh: line 5: docker: not found

Hi Michael,now I have the same issue,and I used the Docker executor with image ruby:2.6,the issue comes when I use it in gitlab-ci.yml。。。。May I ask your help?

I encountered a similar error during my CI/CD pipeline execution:
$ echo “Executing CI/CD pipeline”
Executing CI/CD pipeline
$ echo “$CI_REGISTRY_PASSWORD” | docker login -u “$CI_REGISTRY_USER” --password-stdin $CONTAINER_REGISTRY
/usr/bin/bash: line 140: docker: command not found
Cleaning up project directory and file based variables 00:00
ERROR: Job failed: exit code 1

Here is my script:

yaml

stages:

  • build
  • deploy

variables:
CONTAINER_REGISTRY: docker.io # Docker Hub
CONTAINER_IMAGE_BACKEND: $CONTAINER_REGISTRY/containerqueen/matieres:backend-latest
EKS_CLUSTER_NAME: matiere_cluster
AWS_DEFAULT_REGION: us-east-1

before_script:

  • echo “Executing CI/CD pipeline”

MASTER

.server_rules_master: &server_rules_master
rules:

  • if: ‘$CI_COMMIT_BRANCH == “master”’
    changes:
  • ./**/*
  • .gitlab-ci.yml

.deploy_rules_master: &deploy_rules_master
rules:

  • if: ‘$CI_COMMIT_BRANCH == “master”’

######################################################### BUILD ###############################################

#Backend
build:
stage: build
image: docker:18.09
services:

  • docker:18.09-dind
    variables:
    DOCKER_DRIVER: overlay2
    DOCKER_HOST: tcp://docker:2375
    IMAGE: ${CI_REGISTRY_IMAGE}/backend
    TAG: master
    FOLDER: .
    before_script:
  • docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    script:
  • docker build -t $IMAGE:$TAG -f $FOLDER/Dockerfile $FOLDER
  • docker push $IMAGE:$TAG

######################################################### DEPLOY ###############################################

Backend

deploy:
stage: deploy
image: docker:latest
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: us-east-1
script:

  • echo “$CI_REGISTRY_PASSWORD” | docker login -u “$CI_REGISTRY_USER” --password-stdin $CONTAINER_REGISTRY
  • docker pull $CONTAINER_IMAGE_BACKEND
  • docker tag $CONTAINER_IMAGE_BACKEND $CONTAINER_IMAGE_BACKEND
- aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
- aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
- aws configure set default.region $AWS_DEFAULT_REGION
- aws eks update-kubeconfig --region $AWS_DEFAULT_REGION --name $EKS_CLUSTER_NAME
- kubectl apply -f deployment.yml
- kubectl rollout restart deployment backend

Can someone help me solve this issue, please?