jurevert
jurevert

Reputation: 878

"failed to fetch builder image ... Cannot connect to the Docker daemon at unix" error while building docker image with buildpacksio/pack

While launching on my laptop (MacOS) OR on my CI/CD tools (Atlassian Bamboo):

docker run --volume "/Users/username/Documents/git/myapp:/data" --workdir /data --rm buildpacksio/pack:latest build myapp:latest --builder paketobuildpacks/builder:base --env "BP_MAVEN_BUILT_ARTIFACT=target/myapp.jar"

I'm facing following error:

ERROR: failed to build: failed to fetch builder image 'index.docker.io/paketobuildpacks/builder:base': Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

I also try following launch in order to solve what I guess is a 'Docker in Docker' issue:

docker run --privileged=true -v "/var/run/docker.sock:/var/run/docker.sock" -v "/Users/username/Documents/git/myapp:/data" --workdir /data --rm buildpacksio/pack:latest build myapp:latest --builder paketobuildpacks/builder:base --env "BP_MAVEN_BUILT_ARTIFACT=target/myapp.jar"

But now facing a 'permission denied' error:

ERROR: failed to build: failed to fetch builder image 'index.docker.io/paketobuildpacks/builder:base': Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.38/images/create?fromImage=paketobuildpacks%2Fbuilder&tag=base": dial unix /var/run/docker.sock: connect: permission denied

My need seems to be common so any help will be appreciated :)

Upvotes: 1

Views: 3546

Answers (2)

jurevert
jurevert

Reputation: 878

TLDR

Use 'buildpacksio/pack:0.13.1' image instead of more recent one.

Details

I do not have any 'docker in docker' issue with image tagged 0.13.1 or lowest.

So it is now working fine with following command:

docker run --privileged=true -v "/var/run/docker.sock:/var/run/docker.sock" -v "/Users/username/Documents/git/myapp:/data" --workdir /data buildpacksio/pack:0.13.1 build myapp:latest --builder paketobuildpacks/builder:base --env "BP_MAVEN_BUILT_ARTIFACT=target/myapp.jar"

Upvotes: 0

Alex
Alex

Reputation: 1639

Can you try mounting the docker.sock file with:

-v "/var/run/docker.sock:/var/run/docker.sock:Z"

I know from experience that without the ":Z" part docker mounts the file as a directory instead.

Update: I'm wrong about the :Z part. It's the part ...:/var/run/docker.sock that tells docker to the file as a file and not a directory. You can remove the :Z suffix.

Upvotes: 1

Related Questions