How to run docker build in a circleci job that uses docker?


#1

I want to use circleci to build and deploy a docker image to a repository when there is a change in the main branch of my github project.

My docker image is based on ubuntu:16.04

When I run docker build it emits this error message:

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

If I try service docker start I got this:

/etc/init.d/docker: 96: ulimit: error setting limit (Operation not permitted)

Has anyone encountered similar issue? If so, what is a solution?


#2

Do you specifically need to base yourself on the plain Ubuntu image? Use docker:17.05.0-ce-git as your base if you want Docker installed and working if you can.


#3

Yes, I need to use an image based on ubuntu because the bespoke docker image is already set up with all the essential dev tools specific to this particular distro for my project.


#4

If you really can’t change, then please show us how you’ve installed Docker - showing the whole config is probably best.


#5

I basically followed the instructions at this url: https://docs.docker.com/install/linux/docker-ce/ubuntu/. The step ‘Install docker’ captures the setup process.

version: 2
jobs:
  build: 
    docker:
      - image: 12345678.dkr.ecr.us-west-1.amazonaws.com/circleci/build:20180319
    steps:
      - checkout
      - run:
          name: Install docker
          command: |
            apt-get update --fix-missing
            apt-get install -y apt-transport-https ca-certificates software-properties-common
            curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
            apt-key fingerprint 0EBFCD88
            add-apt-repository \
              "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
              $(lsb_release -cs) \
              stable"
            apt-get update
            apt-get install -y docker-ce
            docker --version
      - run:
          name: Build and deploy docker images
          command: pynt build_and_deploy_docker_images

What is missing in the above is service docker start which failed due to the ulimit problem


#6

I’ve not come across the error before, but this simple search revealed this similar problem.

(I added “sudo” to my search terms, as some Docker permission problems are related to whether one is a member of the docker group or not. However, on reading those answers, I think that’s a red herring).


#7

The ‘answer’ you cited is not applicable. My question is about overcoming the ulimit problem when starting docker daemon.


#8

I’m assuming you’ve read https://circleci.com/docs/2.0/building-docker-images.
Rolling your own and manually starting your own docker is highly non-standard but I’m sure it’s doable.
I can’t give you the answer you want, but I suggest basing your build:20180319 and all its pynt goodies off of an official circleci image such as circleci/python:2.7.14. Then in config.yml

  1. Remove all the docker installation stuff
  2. Remove the service start docker
  3. Add a setup_remote_docker incantation as per the docs

#9

This approach works very well indeed. I do this because I operate a microservices app, and spinning it up in Circle using Docker Compose was fairly straightforward, because that’s how I run it locally and in production.


#10

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