I've seen a lot of people ask the question: How to execute docker inside of a docker container? And there can actually be a use case for that.
The most obvious use case for me was a Jenkins container, that needs to execute docker commands in order to build and push the image in docker repo in its build jobs.
There are 3 ways to do it:
get a ready Jenkins image with docker pre-installed
install docker yourself in the Jenkins official image (by adjusting the Dockerfile and rebuilding the image)
use docker installed on the host where the container is running. -> This is the option I have used
In order to get the docker from host into the container, you need to mount the docker installation path on the host into the Jenkins container.
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: jenkins
spec:
template:
spec:
containers:
- image: jenkins
name: jenkins
...
volumeMounts:
- mountPath: /var/run/docker.sock
name: docker-sock
...
volumes:
- name: docker-sock
hostPath:
path: /var/run/docker.sock
Now when this Jenkins container starts you will have docker commands available inside.
Top comments (0)