Docker in Docker 实践 on mac
在尝试tekton构建ci pipeline是,需要在k8 pod里build image,于是研究了如何docker in docker。
1. 编写自己的dind docker image
FROM docker:20.10.16-dind
ENV DOCKER_HOST unix:///var/run/docker.sock
2. docker build 自己的dind docker image并push到repo上
docker build . -t cara/my-dind-docker:latest
docker push cara/my-dind-docker:latest
3. 启动container,并挂载本地的docker socket到该container
docker run -v /var/run/docker.sock:/var/run/docker.sock -ti cara/my-dind-docker:latest /bin/sh
4. 在container内部,使用docker指令就可以了
carawang@docker_base %docker run -v /var/run/docker.sock:/var/run/docker.sock -ti cara/my-dind-docker:latest sh
/ #
/ # ls
bin dev home lib64 mnt proc run srv tmp var
certs etc lib media opt root sbin sys usr
/ # docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
21cfcc3e6a32 cara/my-dind-docker:latest "dockerd-entrypoint.…" 6 seconds ago Up 5 seconds 2375-2376/tcp thirsty_cray
da2c32df0751 cara/my-dind-docker:latest "dockerd-entrypoint.…" 28 minutes ago Up 28 minutes 0.0.0.0:80->80/tcp, 2375-2376/tcp my-dind-container
e0763051d1c4 gcr.io/k8s-minikube/kicbase:v0.0.44 "/usr/local/bin/entr…" 10 days ago Up 37 minutes 127.0.0.1:49709->22/tcp, 127.0.0.1:49710->2376/tcp, 127.0.0.1:49712->5000/tcp, 127.0.0.1:49713->8443/tcp, 127.0.0.1:49711->32443/tcp minikube
/ #