0

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

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

3 Answers 3

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!

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

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" 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.