Dockerfile에는 일반적으로 서버에서 애플리케이션을 실행하는 데 사용하는 단계와 유사한 단계가 있다.
- 운영 체제로 시작
- 언어 런타임 설치
- 모든 애플리케이션 종속성 설치
- 실행 환경 설정
- 애플리케이션 실행
참고: OS 및 언어 런타임이 사전 설치된 기본 이미지를 선택하면 3번으로 바로 이동할 수 있는 경우가 많다.
유용한 기술
이러한 기술 적용의 영향
일반적으로 이러한 기술은 (1) 빌드 속도, (2) 이미지 보안 및 (3) 개발자 명확성의 일부 조합에 영향을 미친다. 다음은 이러한 영향을 요약한 것.
Legend:
🔒 Security
🏎️ Build Speed
👁️ Clarity
Pin specific versions [🔒 👁️]
Use small + secure base images [🔒 🏎️]
Protect the layer cache [🏎️ 👁️]
Be explicit [🔒 👁️]
Avoid unnecessary files [🔒 🏎️ 👁️]
Use non-root USER [🔒]
Install only production dependencies [🔒 🏎️ 👁️]
Avoid leaking sensitive information [🔒]
Leverage multi-stage builds [🔒 🏎️]
컨테이너의 기본 이미지를 선택할 때 크기, 언어 지원, 인체공학, 보안과 같은 요소를 고려하는 것이 중요하다. 이러한 고려 사항에 대해 논의하고 Node.js 애플리케이션에 대한 몇 가지 샘플 이미지를 확인해보자.
고려해야 할 요소들
크기: 기본이미지 사이즈는 최종 이미지 사이즈의 처음 값
언어지원: 기본이지미가 해당 언어를 지원하고 있는지 확인
인체공학:이미지 작업이 얼마나 쉬운지, 디버깅이나 패키지 설치를 위한 유틸리티가 내장되어 있는지.
보안: CVE(취약점과 노출성) 수와 이미지의 공격 노출 영역을 고려
node.js 어플리케이션의 기본이미지 예시

위 사진은 node.js 어플리케이션 기본이미지와 각각의 취약점과 사이즈에 대한 예시이다.
node:latest (Bullseye) - Almost 1 GB in size, with 5 critical vulnerabilities, but easy to work with.
node:slim (Bullseye) - 4 times smaller than the full size image and eliminates critical vulnerabilities, but with fewer built-in utilities.
node:alpine - Small and free of CVEs, but considered experimental by Node.js due to its different C library variant.
gcr.io/distroless/nodejs - Security-focused image created by Google, with LTS Node.js support only and limited utilities.
cgr.dev/chainguard/node - Smallest and most secure image, but may be more difficult to work with due to its software provenance and limited package support.