Docker Image Layer

Human Being·2022년 4월 30일
0

Docker

목록 보기
4/8
post-thumbnail

Dockerfile을 잘 작성하는 법에 대해서
docker 사에서 소개하는 내용이다
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/

Minimize the number of layers

In older versions of Docker, it was important that you minimized the number of layers in your images to ensure they were performant. The following features were added to reduce this limitation:

  • Only the instructions RUN, COPY, ADD create layers. Other instructions create temporary intermediate images, and do not increase the size of the build.

RUN, COPY, ADD 사용할 때마다 하나의 layer가 생성되어
build 시 크기가 증가하기에
최소한으로 사용해야 한다고 나와있다

여기서 얘기하는 layer가
바로 docker image layer이다

docker image layer 직접 보기

ubuntu를 위한 dockerfile은 너무나도 짧아서
python image를 기반으로 설명하려 한다

python 3.10을 pull 받았다

해당 image를 만들기 위해 사용된 layer를 살펴보려면
다음과 같이 입력한다

docker image history {image name or id}

각 한 줄이 하나의 layer를 의미하며
맨 상단의 최근 layer 순으로 나열된다
이를 이용하여 각 layer의 크기를 볼 수 있다

(BY에 나온 명령줄을 다 보고 싶다면 --no-trunc 옵션을 추가하면 된다)

docker image layer 개념

docker 사에서 나타낸 그림

위의 사진에서 IMAGE가 missing인 줄이 바로
아래 그림에서 Image Layers (R/O)이다
R/O는 Read only로 Container 내부로 들어가도 건드릴 수 없는 영역이다

결국 layer 중에서 run할 때마다 달라질 수 있는 곳은
R/W (Read & Write) layer다
이 부분은 Dockerfile에서 CMD 명령어를 통해
기본 실행문을 명시할 수 있다

그래서 아래 그림은 각 container 별로 R/W layer는 달라질 수 있지만
image는 공통된 내용을 기반한다는 모습을 설명하고 있다

출처 : https://docs.docker.com/storage/storagedriver/

0개의 댓글