Getting "Cannot connect to the Docker daemon" while testing Docker image using Docker Stack

Hello team,

I am using below cofiguration circle ci to test docker stack.

version: 2
jobs:
  test:
    docker:
      - image: circleci/python:3.7
    steps:
      - checkout
      - run: echo "Initializing build with docker stack
      - run: docker stack deploy -c stack.yml bitroid
      - run: curl localhost
  
  deploy:
    machine:
      enabled: true
    steps:
      - checkout
      - run:
          name: Deploy Master to Heroku
          command: |
            - $HUB_DOCKER_TRIGGER
      
workflows:
  version: 2
  test_and_deploy:
    jobs:
      - test
      - deploy:
          requires:
            - test

It is throwing below error in circle ci .

#!/bin/bash -eo pipefail
docker stack deploy -c stack.yml bitroid
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Exited with code 1

Can you please check and advice.

Thanks and regards,
Hemanth.

Hello team,

After trying hit and trail logic for me this issue is resolved partially with below logic.
I am facing issue from deploy tag.

version: 2
jobs:
  test:
    working_directory: /app
    docker:
      #- image:18.06.0-ce-git
      - image: docker:17.05.0-ce-git
    steps:
      - checkout
      - setup_remote_docker
      - run:
          name: Install dependencies
          command: |
            apk add --no-cache \
              py-pip=9.0.0-r1
            apk --no-cache add curl
            pip install wget
            pip install \
              docker-compose==1.12.0 \
              awscli==1.11.76
      - run: echo "Initializing build with docker stack"
      - run: docker swarm init
      - run: docker stack deploy -c stackfile.yml bitroid
      - run: docker service ls
  
  deploy:
    machine:
      enabled: true
    steps:
      - checkout
      - run:
          name: Deploy Master to Heroku
          command: |
            - $HUB_DOCKER_TRIGGER
      
workflows:
  version: 2
  test_and_deploy:
    jobs:
      - test
      - deploy:
          requires:
            - test

I am getting below error from deploy tag in circle ci.

#!/bin/bash -eo pipefail
- $HUB_DOCKER_TRIGGER
/bin/bash: - : invalid option
Exited with code 1

Can anyone advise urgently,

Thanks,
Hemanth.

Hello team,

You can ignore this issue.
Issue is solved with below script.

version: 2
jobs:
  test:
    working_directory: /app
    docker:
      #- image:18.06.0-ce-git
      - image: docker:17.05.0-ce-git
    steps:
      - checkout
      - setup_remote_docker
      - run:
          name: Install dependencies
          command: |
            apk add --no-cache \
              py-pip=9.0.0-r1
            apk --no-cache add curl
            pip install wget
            pip install \
              docker-compose==1.12.0 \
              awscli==1.11.76
      - run: echo "Initializing build with docker stack"
      - run: docker swarm init
      - run: docker stack deploy -c stackfile.yml bitroid
      - run: sleep 90
      - run: docker service ps bitroid_app
      - run: docker service ls
      - run: docker ps -a
  
  deploy:
    machine:
      enabled: true
    steps:
      - checkout
      - run:
          name: Trigger build in docker hub.
          command: $HUB_DOCKER_TRIGGER
      
workflows:
  version: 2
  test_and_deploy:
    jobs:
      - test
      - deploy:
          requires:
            - test

Great stuff, I love it when self-fixes are posted :smiley_cat:

I don’t know the purpose of the sleep 90, but that seems like an awfully long time. Can you replace it with a shell script that tests to see if a service is up? I wonder if that would bring the wait time down considerably, while being resilient to unusually slow starts.

I have added sleep time so that service can go to running state within 90 seconds.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.