사이드카를 이용한 Docker-in-Docker (Docker-in-Docker Using Sidecars)
본문
!!! Note "Alternatives" Alternative methods of building containers, such as Kaniko or Buildkit can be simpler and more secure. See the Buildkit template as an example.
사이드카(sidecars)를 사용해 Docker-in-Docker(DIND)를 구현할 수 있습니다. DIND를 사용하면 컨테이너 이미지 빌드·푸시처럼 컨테이너 안에서 Docker 명령을 실행할 수 있습니다.
다음 예제는 docker:dind 이미지를 사용해 사이드카에서 Docker 데몬을 실행하고, 메인 컨테이너가 그 데몬에 접근할 수 있게 합니다:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: sidecar-dind-
spec:
entrypoint: dind-sidecar-example
templates:
- name: dind-sidecar-example
container:
image: docker:19.03.13
command: [sh, -c]
args: ["until docker ps; do sleep 3; done; docker run --rm debian:latest cat /etc/os-release"]
env:
- name: DOCKER_HOST # the docker daemon can be access on the standard port on localhost
value: 127.0.0.1
sidecars:
- name: dind
image: docker:19.03.13-dind # Docker already provides an image for running a Docker daemon
command: [dockerd-entrypoint.sh]
env:
- name: DOCKER_TLS_CERTDIR # Docker TLS env config
value: ""
securityContext:
privileged: true # the Docker daemon can only run in a privileged container
# mirrorVolumeMounts will mount the same volumes specified in the main container
# to the sidecar (including artifacts), at the same mountPaths. This enables
# dind daemon to (partially) see the same filesystem as the main container in
# order to use features such as docker volume binding.
mirrorVolumeMounts: true
더 알아보기 (Learn more)
- DIND 사이드카는
privileged: true가 필요하고, 메인 컨테이너는DOCKER_HOST=127.0.0.1로 데몬에 접속합니다. mirrorVolumeMounts: true를 쓰면 메인 컨테이너의 볼륨(아티팩트 포함)이 같은 경로로 사이드카에도 마운트됩니다.- 더 단순하고 안전한 빌드가 필요하면 Kaniko나 Buildkit 템플릿을 먼저 검토하세요.