I am using the docker dind image and creating a pod. When I try to run docker build inside the pod, I get an error.
apiVersion: v1
kind: Pod
metadata:
name: dockercontainer
namespace: default
spec:
containers:
- image: docker:24.0.0-rc.1-dind
name: dockercontainer
securityContext:
runAsUser: 0
The pod is getting created, but when I execute a docker build inside the pod, I get the following error:
ERROR: Cannot connect to the docker daemon at unix://var/run/docker.sock
2
Answers
Can you check the OS Distro? Plz run this command
cat /etc/os-release
. As for the error message, it looks like the docker Daemon isn’t running. Can you try running this commandsudo dockerd &
?You can read more about dockerd here. For ArchLinux, I had posted a similar answer here.
NOTE: this assumes that you’re using a docker runtime in K8s! If not, use kaniko.
The docker daemon isn’t mounted into the pod – this is the reason for your error. In order to build images, you will need one of these:
privileged
modeThere are some issues w/ building/running containers w/in a K8s pod, from a security standpoint (more on this here and here). Much safer approach is to use sysbox but that’s perhaps more detailed than we want to get here.
I’m assuming that it’s not possible for you to be able to build this image outside of K8s.