I have an application which needs docker and the application checks for docker deamon when it starts. I can not get away with this as it is a 3rd party application.
So, getting error when i tried to deploy this app on kubernetes.
Failed to run 'docker -H unix:///var/run/docker.sock ps -a': exited with status 1; stderr='Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
I am not sure if kubernetes is internally using docker deamon for spinning up containers. Is there any way to get around with this?
Thanks
kubernetes by default uses docker also as a container runtime, so this means you need a docker within docker. it is possible generally, but needs some extra configuration and privileges. start with this official docker blog article which should give you some pointers how to achieve it.
There are two ways to run Docker in the Kubernetes application.
Docker Out Of Docker. Here you have to mount host's /var/run/docker.sock on your container. It'll connect to the host's Daemon through it. But it is more vulnerable.
Docker IN Docker. It is a container that runs both Docker Daemon and Docker cli by itself. Here we don't need to mount /var/run/docker.sock into the container. More secure than DOOD.
Kubernetes can run without docker, but the app you're running requires to connect to docker. Could you try to run it with docker desktop running?
You can mount the docker socket file in your deployment.
docker container run -d \
-v /var/run/docker.sock:/var/run/docker.sock <image-name>
Similar changes can be added to Kubernetes deployment too.
Now, your application can connect with the docker daemon running in your local system.
However, it is not a good practice as it compromises the security isolations provided by docker.
Looks like is a docker-compose.yml and you need it. Now docker have a version with kubernetes and you dont have started/installed docker and if you want to use kubernetes in docker make sure is activiated kubernetes in your docker settings like this: