Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running

I am using gitlab ci for continues integration, I want to run unit test on my code and then build a docker image and then deploy it. But the problem which I am facing is that how to run a docker service in gilab ci.

I get this error

"Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running"

after my docker build command is run. do I need to install docker in gitlab-ci?

This is my .gitlab-ci.yml file

image: node:latest

before_script:

stages:
  - test
  - production
  - clean_up

services:
  - docker:dind

test:
  stage: test
  script:
    - npm install
    - npm install -g swagger
    - npm test

production:
  type: deploy
  stage: production
  image: docker:latest
  script:
    - docker build -t testimage -t testimage:latest .
    - docker tag testimage docker.abc.xyz.com/testimage
    - docker push docker.abc.xyz.com/testimage
  only:
    - development

clean_up_job:
  stage: clean_up
  script:
    - rm -rf node_modules
    - npm uninstall -g swagger
  when: on_failure

I am not using GitLab Runner at the moment.

like image 529
user3649361 Avatar asked Jul 18 '17 11:07

user3649361


1 Answers

Try putting services inside production job, like this:

production:
  type: deploy
  stage: production
  image: docker:latest
  services:
    - docker:dind
  script:
    - docker build -t testimage -t testimage:latest .
    - docker tag testimage docker.abc.xyz.com/testimage
    - docker push docker.abc.xyz.com/testimage
  only:
    - development
like image 171
Izydorr Avatar answered Sep 18 '22 14:09

Izydorr