본문 바로가기

클라우드/도커(Docker)

도커 Docker 레이어 (Layer) , Port (포트)

 

더보기

# ubuntu:20.04 Layer
vagrant@docker:~$ docker inspect ubuntu:20.04
RootFS":
            "Layers": [
                "sha256:feef05f055c989eea0367f5d3a2cba79896dd6d8a8b72bea2c729548a4ca5aef"


#Dockerfile 생성
vagrant@docker:~/build$ vi Dockerfile 
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND noninteractive  # 패지키를 설치할때 대화형 모드로 물어보지 않는다                       
RUN ["apt", "update"]
RUN ["apt", "install", "-y", "apache2"]
ENTRYPOINT ["apachectl"]
CMD ["-D", "FOREGROUND"]
EXPOSE 80/tcp                       # 기본값이 tcp 이기때문에 생략가능
ADD ports.conf /etc/apache2/ports.conf
COPY index.html /var/www/html/index.html

파일이 변경,추가,삭제 되면 레이어로 저장
-> RUN ADD COPY -> 레이어 생성 

# FROM ubuntu:20.04 도커파일을 이용하여 만든 v1 이미지 Layer
vagrant@docker:~$ docker inspect ldh:v1
RootFS":
                "sha256:feef05f055c989eea0367f5d3a2cba79896dd6d8a8b72bea2c729548a4ca5aef",
                "sha256:f3221ea1b2befe9ad495e1ec2260b3dffec88667a03d6010fe1fb01f41cfeddb",
                "sha256:f5cc3095ab8ffc21f19394c73899c2d49fb95f12ddf2b3fbd90ba42c79af2c45",
                "sha256:a53dfee78ca473ff400908168ffbb9d15cab616dc33dc4a34a410bee9392398e",
                "sha256:e5337e51e69bc3ad21f1e82815acb6972b813de272a6aeadfc1bf024a1ebfb43"
-> ubuntu:20.04 이미지에 레이어가 추가 되었다


# 도커파일을 변경하지 않고 만든 v2 이미지 Layer
vagrant@docker:~$ docker inspect ldh:v2
RootFS": 
                "sha256:feef05f055c989eea0367f5d3a2cba79896dd6d8a8b72bea2c729548a4ca5aef",
                "sha256:f3221ea1b2befe9ad495e1ec2260b3dffec88667a03d6010fe1fb01f41cfeddb",
                "sha256:f5cc3095ab8ffc21f19394c73899c2d49fb95f12ddf2b3fbd90ba42c79af2c45",
                "sha256:a53dfee78ca473ff400908168ffbb9d15cab616dc33dc4a34a410bee9392398e",
                "sha256:e5337e51e69bc3ad21f1e82815acb6972b813de272a6aeadfc1bf024a1ebfb43"
-> v1 이미지 레이어와 같다


# 도커파일 일부분을 변경하고 만든 v3 이미지 Layer   
vagrant@docker:~$ docker inspect ldh:v3
"RootFS": 
                "sha256:feef05f055c989eea0367f5d3a2cba79896dd6d8a8b72bea2c729548a4ca5aef",
                "sha256:f3221ea1b2befe9ad495e1ec2260b3dffec88667a03d6010fe1fb01f41cfeddb",
                "sha256:f5cc3095ab8ffc21f19394c73899c2d49fb95f12ddf2b3fbd90ba42c79af2c45",
                "sha256:eb312f95fe1d0964cb94df3405d251300e3bac7a102e2e9b17d877b93f4172be",
                "sha256:d43c1fafa9a291e6a66c9e78becec28ecea6226808b7076d974964f494628e40"
-> v1,v2 이미지 레이어와 일부 다르다


vagrant@docker:~/build$ docker images
REPOSITORY        TAG       IMAGE ID       CREATED         SIZE
ldh               v3        f381498fdecd   5 minutes ago   215MB
ldh               v2        99bf895fb720   2 days ago      215MB
ldh               v1        99bf895fb720   2 days ago      215MB


# 이미지로 컨테이너를 만들면
# 컨테이너에는 레이어가 하나 더 생긴다

"LowerDir": 
"/var/lib/docker/overlay2/89d6714f0480fe91b8a85f50e86e141ae03623d3ca1ede8c44ef14d9e406ccae-init/diff:
/var/lib/docker/overlay2/60250cb05393e8f66b85ece50073f6bd6f38614d4c3251d269cbd4409d886297/diff:
/var/lib/docker/overlay2/3f3de108d303449771ecbbea5e0870d4a0863665a249e2571ebe2843d3a097ec/diff:
/var/lib/docker/overlay2/852096cfc64b37dcdecb04cb4a4edd6c692829cfaa10ccacbea9d8f3b26ff0f3/diff:
/var/lib/docker/overlay2/d51a442dadda159110e106322b0f27defda4aed94dd24ba144cbc174495a9f01/diff:
/var/lib/docker/overlay2/afbc2512c3872655f02c9aaab53b4ed0f01604ec61de40184d2107b507569f98/diff",




더보기

vagrant@docker:~/build$ docker run -d -p 80:8080 ldh:v5

vagrant@docker:~/build$ docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                   NAMES
60e2e3fe0590   ldh:v5    "apachectl -D FOREGR…"   5 seconds ago   Up 5 seconds   0.0.0.0:80->8080/tcp, :::80->8080/tcp   loving_bardeen

vagrant@docker:~/build$ curl localhost
ldh
vagrant@docker:~/build$ curl localhost:8080
curl: (7) Failed to connect to localhost port 8080: Connection refused

dockerfile의 export 실제 서비스 포트랑은 관련없보를
- 단순 정보 이미지를 사용하는 사람이 정보를 받기위해 정보 제공

80:8080
80으로 접속해주면 8080으로 보내준다


 

 

Layer 확인하는 법

 

고템플릿