Answers: <p>If the docker is actually installed on the runner machine, it's possible that it's not in the PATH variable for runner. Try adding it manually with:</p>
  <pre><code>variables:
    PATH: &quot;/path/to/docker:$PATH&quot; 
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2024-04-28T08:57:49.013Z
Answers: 2024-04-28T08:57:49.013Z
Answers: Vasilii Angapov
Answers: <p>Your .gitlab-ci.yml and Dockerfile are fine, the problem is on the Gitlab Runner that executes the CI pipeline.</p>
  <p>The runner cannot access its Docker Engine, either because it is not installed  on the runner or the runner is not configured to run in <code>privileged</code> mode, which is necessary to use Docker in your CI.</p>
  <ol>
  <li><p>Check if Docker is installed
  If you have access to the machine which hosts the runner, check if Docker is installed there
  <a href="https://docs.docker.com/engine/install/" rel="nofollow noreferrer">https://docs.docker.com/engine/install/</a></p>
  </li>
  <li><p>Active privileged mode in the Gitlab Runner Configuration</p>
  </li>
  </ol>
  <p>in config.toml:</p>
  <p><code>privileged = true</code></p>
  <p><a href="https://docs.gitlab.com/runner/configuration/advanced-configuration.html" rel="nofollow noreferrer">https://docs.gitlab.com/runner/configuration/advanced-configuration.html</a></p>
  <p>Also check the Gitlab CI Documentation on how to use Docker here
  <a href="https://docs.gitlab.com/ee/ci/docker/using_docker_build.html" rel="nofollow noreferrer">https://docs.gitlab.com/ee/ci/docker/using_docker_build.html</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2023-04-03T15:02:37.503Z
Answers: 2023-04-03T15:02:37.503Z
Answers: Lukas Zech
Answers: <p>Do you know for sure if Docker is installed on the machine/VM that has the runner on it?  Depending on your setup, you can SSH into the machines that host the Gitlab runners and just do <code>docker --version</code>.</p>
  <p>If it's not on there, then you will need to visit <a href="https://docs.docker.com/engine/install/" rel="nofollow noreferrer">https://docs.docker.com/engine/install/</a> and add it.</p>
  <p>I ran into the same situation, coming into a project that used GitLab runners with no prior experience - at the end of the day, a GitLab runner is just a program that can run on any machine.  Depending on how your CI/CD is configured, it may be on a development VM, server, workstation, etc.  Good luck!</p>
  
Answers: CC BY-SA 4.0
Answers: 2022-11-01T17:27:37.920Z
Answers: 2022-11-01T17:27:37.920Z
Answers: Mrschwifty
Body: <p>I'm trying to build docker container using GitLab runner.
  (lead dev left company, and now I have no idea how to do it.)</p>
  <p>I'll share everything I can.</p>
  <p>Build output
  <a href="https://i.sstatic.net/CvDFj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CvDFj.png" alt="output error" /></a></p>
  <p>as I understand from output runner is assigned correctly, the problem is with docker</p>
  <p><em><strong>the runner is running as Shell executor</strong></em></p>
  <p>here is <strong>.gitlab-ci.yml</strong></p>
  <pre><code>stages:
    - build
    - deploy
  
  variables:
    STACK_NAME: isnta_api
    VERSION: ${CI_COMMIT_TAG}
    IMAGE_NAME: ${DOCKER_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_TAG}
  
  before_script:
    - echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
    - echo $STACK_NAME
    - echo $CI_REGISTRY
    - echo $IMAGE_NAME
  
  build:
    stage: build
    only:
      - tags
    script:
      - docker build -f Dockerfile -t ${IMAGE_NAME}  .
      - docker push ${IMAGE_NAME}
  
  deploy:
    stage: deploy
    only:
      - tags
    script:
      - docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${STACK_NAME}
  
  </code></pre>
  <p><strong>docker-compose.yml</strong></p>
  <pre><code>version: '3.7'
  
  services:
    app:
      container_name: ${STACK_NAME}
      image: ${IMAGE_NAME}
      environment:
        PORT: 4042
        APP_ENV: production
        INSTAGRAM_API_KEY: de194cf559msh8d940d38fd1ca47p129005jsnc11b4fd77a36
        INSTAGRAM_API_HOST_NAME: instagram-bulk-profile-scrapper.p.rapidapi.com
        INSTAGRAM_API_BASE_URL: https://instagram-bulk-profile-scrapper.p.rapidapi.com/clients/api/ig/
      networks:
        - nxnet
      ports:
        - 4042:4042
      deploy:
        replicas: 1
        update_config:
          order: start-first
  
  networks:
    nxnet:
      external: true
  
  </code></pre>
  <p>and <strong>Dockerfile</strong></p>
  <pre><code>FROM node:14-alpine
  
  COPY . /app
  
  WORKDIR /app
  RUN apk add --no-cache bash
  RUN npm install
  
  RUN npm run build
  
  CMD npm run start:prod
  
  </code></pre>
  <p>Any suggestions or tips would be valuable. Thank you in advance</p>
  
Tags: <docker><gitlab><gitlab-ci-runner>
Title: gitlab-runner docker: command not found
UserDisplayName: Andronik Nazaryan
ThreadText: # gitlab-runner docker: command not found
  
  (Asked by: username_0 on 2022-08-03)
  
  I'm trying to build docker container using GitLab runner.
  (lead dev left company, and now I have no idea how to do it.)
  
  I'll share everything I can.
  
  Build output
  [![output error](https://i.sstatic.net/CvDFj.png)](https://i.sstatic.net/CvDFj.png)
  
  as I understand from output runner is assigned correctly, the problem is with docker
  
  ***the runner is running as Shell executor***
  
  here is **.gitlab-ci.yml**
  
  ```
  stages:
    - build
    - deploy
  
  variables:
    STACK_NAME: isnta_api
    VERSION: ${CI_COMMIT_TAG}
    IMAGE_NAME: ${DOCKER_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_TAG}
  
  before_script:
    - echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
    - echo $STACK_NAME
    - echo $CI_REGISTRY
    - echo $IMAGE_NAME
  
  build:
    stage: build
    only:
      - tags
    script:
      - docker build -f Dockerfile -t ${IMAGE_NAME}  .
      - docker push ${IMAGE_NAME}
  
  deploy:
    stage: deploy
    only:
      - tags
    script:
      - docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${STACK_NAME}
  
  ```
  
  **docker-compose.yml**
  
  ```
  version: '3.7'
  
  services:
    app:
      container_name: ${STACK_NAME}
      image: ${IMAGE_NAME}
      environment:
        PORT: 4042
        APP_ENV: production
        INSTAGRAM_API_KEY: de194cf559msh8d940d38fd1ca47p129005jsnc11b4fd77a36
        INSTAGRAM_API_HOST_NAME: instagram-bulk-profile-scrapper.p.rapidapi.com
        INSTAGRAM_API_BASE_URL: https://instagram-bulk-profile-scrapper.p.rapidapi.com/clients/api/ig/
      networks:
        - nxnet
      ports:
        - 4042:4042
      deploy:
        replicas: 1
        update_config:
          order: start-first
  
  networks:
    nxnet:
      external: true
  
  ```
  
  and **Dockerfile**
  
  ```
  FROM node:14-alpine
  
  COPY . /app
  
  WORKDIR /app
  RUN apk add --no-cache bash
  RUN npm install
  
  RUN npm run build
  
  CMD npm run start:prod
  
  ```
  
  Any suggestions or tips would be valuable. Thank you in advance
  
  **Tags:** docker, gitlab, gitlab-ci-runner
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2024-04-28. Score: 0
  
  If the docker is actually installed on the runner machine, it's possible that it's not in the PATH variable for runner. Try adding it manually with:
  
  ```
  variables:
    PATH: "/path/to/docker:$PATH" 
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2023-04-03. Score: 0
  
  Your .gitlab-ci.yml and Dockerfile are fine, the problem is on the Gitlab Runner that executes the CI pipeline.
  
  The runner cannot access its Docker Engine, either because it is not installed on the runner or the runner is not configured to run in `privileged` mode, which is necessary to use Docker in your CI.
  
  1. Check if Docker is installed
     If you have access to the machine which hosts the runner, check if Docker is installed there
     <https://docs.docker.com/engine/install/>
  2. Active privileged mode in the Gitlab Runner Configuration
  
  in config.toml:
  
  `privileged = true`
  
  <https://docs.gitlab.com/runner/configuration/advanced-configuration.html>
  
  Also check the Gitlab CI Documentation on how to use Docker here
  <https://docs.gitlab.com/ee/ci/docker/using_docker_build.html>
  
  
  ---
  
  ### Answer by username_3 on 2022-11-01. Score: 0
  
  Do you know for sure if Docker is installed on the machine/VM that has the runner on it? Depending on your setup, you can SSH into the machines that host the Gitlab runners and just do `docker --version`.
  
  If it's not on there, then you will need to visit <https://docs.docker.com/engine/install/> and add it.
  
  I ran into the same situation, coming into a project that used GitLab runners with no prior experience - at the end of the day, a GitLab runner is just a program that can run on any machine. Depending on how your CI/CD is configured, it may be on a development VM, server, workstation, etc. Good luck!
  
  
  ---
  
  