Build Docker image

Hello,
I have problem in circleci jobs. I have configure my circleci to bitbucket so when I push the changes then a job created in circleci but it thors following error :
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
I have attached screenshot also for that.
When I run the command : circleci local execute in my terminal then it execute successfull…!

My config.yml code is here:

version: 2
jobs: # a collection of steps
  build:
    docker:
      - image: circleci/php:7.0.22-apache-node #
        environment:
          IMAGE_NAME: adilkadiyawala/uc2:tagname
          IMAGE: uc2-test
          DOCKERHUB_PASS: PASSWORD
          DOCKERHUB_USERNAME: username
    working_directory: ~/app # directory where steps will run
    steps: # a set of executable commands
      - checkout
      - setup_remote_docker:
          docker_layer_caching: true
      - run:
          name: Build Docker image
          command: |
            sudo docker build --file .docker/Dockerfile -t uc2-test .
          no_output_timeout: 35m
      - run:
          name: Publish Docker Image to Docker Hub
          command: |
            IMAGE_TAG="0.0.${CIRCLE_BUILD_NUM}"
            sudo docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASS
            sudo docker tag $IMAGE:latest $IMAGE_NAME
            sudo docker push $IMAGE_NAME
      - persist_to_workspace:
          root: ~/app
          paths:
            - "vendor" 
            - "generated"
            - "pub/static"
            - "var/view_preprocessed"
            - "image.tar"
workflows:
  version: 2
  build-deploy:
    jobs:
      - build
      - deploy:
          requires:
            - build
          filters:   
            branches:
              only: master
      - deploy-staging:
          requires:
          - build
          filters:
            branches:
              only: staging

Yep, remove all your sudos - you don’t need them. I suspect that runs as a user that is not in the docker group.

@halfer,
Thanks for your replay.
It’s throwing error :
WARNING: Error loading config file: /home/circleci/.docker/config.json - stat /home/circleci/.docker/config.json: permission denied

I would guess you still have sudo for your docker login?

Hi @halfer
It is successfully buiold with sudo. Thanks a lot :slight_smile:
Now I am trying for deploy.
Can you please tell me about the ssh_key to deploy and deploy-staging?
both are different?

Could you give it a go first, by referencing the documentation? If I were to advise you, I’d need to read the docs - so you might as well do it :grin:

Once you have some config and have given it a thorough try, that’s the right time to ask for advice.