정상동작 여부를 체크할때 사용.
root@template:~/Lab# cat Dockerfile.6
FROM ubuntu
RUN apt-get -y update && apt-get -y install nginx curl
EXPOSE 80
COPY index.html /var/www/html/
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost/index.html || exit 1
<---실패하면 리턴값 1 반환해라
CMD ["nginx", "-g", "daemon off ;" ]
root@template:~/Lab#
root@template:~/Lab# echo $? <----------------------------- 확인법
0
exit 명령어 이해하기
---------------------------------------------------------------
root@template:~/Lab#
root@template:~/Lab# sh
# ps --forest
PID TTY TIME CMD
193714 pts/2 00:00:00 bash
251228 pts/2 00:00:00 \_ sh
251325 pts/2 00:00:00 \_ ps
#
#
# exit 7
root@template:~/Lab# echo $?
7
root@template:~/Lab#
root@template:~/Lab# docker run -d -it --name www1 -p 80:80 myimage:3.0
01f595ee0fb2755c27c9151dd7437ecc04e32d04ea5ef5fb25344f68db90a26f
root@template:~/Lab# docker inspect www1
"Healthcheck": {
"Test": [
"CMD-SHELL",
"curl -f http://localhost/index.html || exit 1"
],
"Interval": 30000000000,
"Timeout": 3000000000
},
root@template:~# watch -n 1 docker ps
Every 1.0s: docker ps template: Sun Jul 31 02:44:57 2022
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
01f595ee0fb2 myimage:3.0 "nginx -g 'daemon of…" 3 minutes ago Up 3 minutes (healthy) 0.0.0.0:80->80/tcp, :::80->80/tcp www1
파일을 삭제하면....
root@template:~/Lab# docker exec -it www1 /bin/bash
root@01f595ee0fb2:/#
root@01f595ee0fb2:/# rm -f /var/www/html/index.html
root@01f595ee0fb2:/# ls /var/www/html/index.html
ls: cannot access '/var/www/html/index.html': No such file or directory
Every 1.0s: docker ps template: Sun Jul 31 02:50:25 2022
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
01f595ee0fb2 myimage:3.0 "nginx -g 'daemon of…" 8 minutes ago Up 8 minutes (unhealthy) 0.0.0.0:80->80/tcp, :::80->80/tcp www1
외부에서 파일 복사하면...정상화됨
root@template:~/Lab# docker cp index.html www1:/var/www/html/index.html
root@template:~/Lab#
root@template:~# watch -n 1 docker ps
Every 1.0s: docker ps template: Sun Jul 31 02:52:46 2022
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
01f595ee0fb2 myimage:3.0 "nginx -g 'daemon of…" 10 minutes ago Up 10 minutes (healthy) 0.0.0.0:80->80/tcp, :::80->80/tcp www1
'Infra > Docker_K8S' 카테고리의 다른 글
Dockerfile 작성법8 - USER (0) | 2022.07.31 |
---|---|
Dockerfile 작성법7 - WORKDIR (0) | 2022.07.31 |
Dockerfile 작성법4 - ONBUILD 개념잡기 (0) | 2022.07.31 |
Dockerfile작성법3 - EXCUTE 방식에서 쉘변수 인식 (0) | 2022.07.31 |
Dockerfile 작성법2 - CMD, ENTRYPOINT (0) | 2022.07.31 |
댓글