# Build Docker image

**URL:** <https://discuss.circleci.com/t/build-docker-image/31395>\
**Category:** Build Environment\
**Tags:** docker, circle-yml\
**Created:** [July 17, 2019, 6:21am UTC](https://discuss.circleci.com/t/build-docker-image/31395 "2019-07-17T06:21:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adil](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@Adil](https://discuss.circleci.com/u/Adil)\
**Post date:** [July 17, 2019, 6:21am UTC](https://discuss.circleci.com/t/build-docker-image/31395/1 "2019-07-17T06:21:09Z")

</div>

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…!

 ![CircleCI](https://global.discourse-cdn.com/circleci/original/3X/8/4/84b3f84b607bd98d2af10754cd922931cab4babd.png)

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
```

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [July 17, 2019, 8:17am UTC](https://discuss.circleci.com/t/build-docker-image/31395/2 "2019-07-17T08:17:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Adil](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@Adil](https://discuss.circleci.com/u/Adil)\
**Post date:** [July 17, 2019, 8:54am UTC](https://discuss.circleci.com/t/build-docker-image/31395/3 "2019-07-17T08:54:40Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [July 17, 2019, 11:52am UTC](https://discuss.circleci.com/t/build-docker-image/31395/4 "2019-07-17T11:52:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Adil](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@Adil](https://discuss.circleci.com/u/Adil)\
**Post date:** [July 17, 2019, 11:54am UTC](https://discuss.circleci.com/t/build-docker-image/31395/5 "2019-07-17T11:54:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [July 17, 2019, 11:59am UTC](https://discuss.circleci.com/t/build-docker-image/31395/6 "2019-07-17T11:59:29Z")

</div>

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 😁

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