-
Dockerfile(ENTRYPOINT, CMD) => YAML Definition file(command, args) 덮어쓰기 과정Kubernetes 2025. 6. 30. 19:00
1. Dockerfile의 ENTRYPOINT는 YAML Definition file의 command에 의해 덮어쓰기된다.
아래 처럼 도커파일이 있고, 이 도커파일로 만들어진 이미지가 webapp-color에 올라가있는데
그 이미지를 Pod Definition file에서 활용해서 pod을 만든다면,
기존 도커 파일의 `ENTRYPOINT`는 Pod Definition file의 `command`에 의해 덮어쓰기 된다.Dockerfile에 설정한 ENTRYPOINT는 YAML 정의서에 command가 명시되면 무시되어 YAML의 command가 실행 대상이 된다.
# DockerFile controlplane ~/webapp-color-2 ➜ cat Dockerfile FROM python:3.6-alpine RUN pip install flask COPY . /opt/ EXPOSE 8080 WORKDIR /opt ENTRYPOINT ["python", "app.py"] CMD ["--color", "red"]# Pod Definition file controlplane ~/webapp-color-2 ➜ cat webapp-color-pod.yaml apiVersion: v1 kind: Pod metadata: name: webapp-green labels: name: webapp-green spec: containers: - name: simple-webapp image: kodekloud/webapp-color command: ["--color","green"]위의 경우, ENTRYPOINT인 `python app.py`가 pod Definition file의 command에 의해 덮어쓰기된다.
ENTRYPOINT가 덮어쓰기되면 CMD도 무시된다.
- 최종적으로 pod definition file에서의 `--color green`만 남는 것이 결과가 된다.
2. Dockerfile과 YAML definition file의 command/args 대응 관계
YAML Definition file(Pod, Deployment...)에서
`command`가 실행 대상 (= Docker `ENTRYPOINT`)
`args`는 그에 대한 인자 (= Docker `CMD`)# DOCKERFILE FROM python:3.6-alpine RUN pip install flask COPY . /opt/ EXPOSE 8080 WORKDIR /opt ENTRYPOINT ["python", "app.py"] ✅ CMD ["--color", "red"] ✅# Pod Definition file controlplane ~/webapp-color-3 ➜ cat webapp-color-pod-2.yaml apiVersion: v1 kind: Pod metadata: name: webapp-green labels: name: webapp-green spec: containers: - name: simple-webapp image: kodekloud/webapp-color command: ["python", "app.py"] ✅ args: ["--color", "pink"] ✅ENTRYPONIT는 command로 덮어쓰고
CMD는 agrs로 덮어쓰니- 결과는 `python app.py --color pink`
3. ENTRYPOINT는 유지하고 CMD만 바꾸고 싶을 때
Dockerfile이 아래와 같을 때
# Dockerfile ENTRYPOINT ["node", "index.js"] CMD ["--env=prod"]
Kubernetes에서 CMD만 바꾸고 싶다면containers: - image: my-app args: ["--env=dev"] # ENTRYPOINT는 유지됨- 결과는 `node index.js --env=dev`
참고 자료
'Kubernetes' 카테고리의 다른 글
[(Kubeadm) K8s 클러스터 구축 3/3] Kubeadm init 및 Node join (0) 2025.10.16 [(Kubeadm) K8s 클러스터 구축 2/3] Kubeadm, Kubelet, Kubectl 설치 (0) 2025.10.15 [(Kubeadm) K8s 클러스터 구축 1/3] Container Runtime 설치 (1) 2025.10.14 CKA 쿠버네티스 자격증 취득과정 기록 (2025. 02 변경 이후) (3) 2025.07.25 PV 확장 원리, Kubernetes CSI Driver (1) 2025.07.09