# 컨테이너 리스트
[root@docker101 ~]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@docker101 ~]# docker images ls
REPOSITORY TAG IMAGE ID CREATED SIZE |
[root@docker101 ~]# docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
Digest: sha256:cb63aa0641a885f54de20f61d152187419e8f6b159ed11a251a09d115fdff9bd
Status: Image is up to date for busybox:latest
busybox 이미지의 레이어 구성 확인
[root@docker101 ~]# docker history busybox
IMAGE CREATED CREATED BY SIZE COMMENT |
[root@docker101 ~]# docker history --no-trunc=true busybox
IMAGE
CREATED CREATED
BY
SIZE COMMENT |
컨테이터 구조 확인
[root@docker101 ~]# docker run -it busybox [root@docker101 ~]# docker inspect a4e3054b4104
[
"ResolvConfPath":
"/var/lib/docker/containers/a4e3054b41042a588a62c1b19228e302a5ff5fc793279a3c34e0c1c912ffb608/resolv.conf", "HostnamePath": "/var/lib/docker/containers/a4e3054b41042a588a62c1b19228e302a5ff5fc793279a3c34e0c1c912ffb608/hostname", "LogPath": "/var/lib/docker/containers/a4e3054b41042a588a62c1b19228e302a5ff5fc793279a3c34e0c1c912ffb608/a4e3054b41042a588a62c1b19228e302a5ff5fc793279a3c34e0c1c912ffb608-json.log", <- 로그정보 확인 가능 "Name": "/sad_aryabhata", 아래는 자원 사용량 제한할 수 있음 "Isolation": "", 패스설정 확인 "MaskedPaths": [ 호스트정보 "Config": { 네트워크 설정 정보 "NetworkSettings": { |
단일 레이어로 export 후 import 테스트
[root@docker101 ~]# docker export a4e3054b4104 > /tmp/mybusybox.tar
[root@docker101 ~]# ls -l /tmp/mybusybox.tar
-rw-r--r--. 1 root root 1383936 Aug 8 01:00 /tmp/mybusybox.tar
[root@docker101 ~]# docker import /tmp/mybusybox.tar yslee:v0808
sha256:ec2e7a882d264e254007e91f891b3f9fef9949b0b1cba64ed3c1487482a1f5d7
[root@docker101 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
yslee v0808 ec2e7a882d26 7 seconds ago 1.16MB
# 인터렉티브모드, 컨테이너 백그라운드 재시작
[root@docker101 ~]# docker run -it ubuntu:latest /bin/bash
root@16e00dd6ff18:/# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 16:03 pts/0 00:00:00 /bin/bash
root 12 1 0 16:03 pts/0 00:00:00 ps -ef
root@16e00dd6ff18:/# exit
exit
[root@docker101 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@docker101 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
16e00dd6ff18 ubuntu:latest "/bin/bash" About a minute ago Exited (0) About a minute ago nifty_noyce
[root@docker101 ~]# docker start 16e00dd6ff18
16e00dd6ff18
[root@docker101 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
16e00dd6ff18 ubuntu:latest "/bin/bash" About a minute ago Up 6 seconds nifty_noyce
[root@docker101 ~]# docker attach nifty_noyc
root@16e00dd6ff18:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
# 컨테이너 stop
[root@docker101 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
16e00dd6ff18 ubuntu:latest "/bin/bash" 4 minutes ago Up 5 seconds nifty_noyce
[root@docker101 ~]# docker stop 16e00dd6ff18
16e00dd6ff18
[root@docker101 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# 컨테이너 daemon mode 재기동
[root@docker101 html]# cd /var/www/html
[root@docker101 html]# echo "HP Education" > /var/www/html/index.html
[root@docker101 ~]# docker run -d -p 80:80 --name=web --restart="on-failure:5" \
> -w /var/www/html -v /var/www/html:/usr/local/apache2/htdocs httpd
90288a0ca2f4212f3a6be52a0ed508a23c0e8e7678f96065181c1e0f1b09654b
[root@docker101 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
90288a0ca2f4 httpd "httpd-foreground" 3 seconds ago Up 2 seconds 0.0.0.0:80->80/tcp web
[root@docker101 html]# curl http://172.17.0.2/index.html
HP Education
[root@docker101 html]# curl http://localhost
HP Education
# host port 8080, 컨테이너 port 80
32e19395d72b519fe1d126107e7681b0ded603362d299cc5e34e672620f81829
[root@docker101 html]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
32e19395d72b httpd "httpd-foreground" 6 seconds ago Up 4 seconds 0.0.0.0:8080->80/tcp web1
90288a0ca2f4 httpd "httpd-foreground" 11 minutes ago Up 11 minutes 0.0.0.0:80->80/tcp web
[root@docker101 html]# curl http://localhost:8080
HP Education
Hello
# 컨테이너 일시 중지, 재시작 (clustering 환경에서 특정 노드 일시 중지)
[root@docker101 html]# docker pause web1
web1
[root@docker101 html]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
32e19395d72b httpd "httpd-foreground" 4 minutes ago Up 4 minutes (Paused) 0.0.0.0:8080->80/tcp web1
90288a0ca2f4 httpd "httpd-foreground" 15 minutes ago Up 15 minutes 0.0.0.0:80->80/tcp web
[root@docker101 html]# curl http://localhost:8080
^C
[root@docker101 html]# docker unpause web1
web1
[root@docker101 html]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
32e19395d72b httpd "httpd-foreground" 4 minutes ago Up 4 minutes 0.0.0.0:8080->80/tcp web1
90288a0ca2f4 httpd "httpd-foreground" 15 minutes ago Up 15 minutes 0.0.0.0:80->80/tcp web
[root@docker101 html]# curl http://localhost:8080
HP Education
Hello
# 동작중인 컨테이너 삭제 (메모리에서 컨테이너를 제거)
[root@docker101 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
32e19395d72b httpd "httpd-foreground" 9 minutes ago Up 9 minutes 0.0.0.0:8080->80/tcp web1
90288a0ca2f4 httpd "httpd-foreground" 20 minutes ago Up 20 minutes 0.0.0.0:80->80/tcp web
[root@docker101 ~]# docker rm web1
Error response from daemon: You cannot remove a running container 32e19395d72b519fe1d126107e7681b0ded603362d299cc5e34e672620f81829. Stop the container before attempting removal or force remove
[root@docker101 ~]# docker rm -f web1
web1
[root@docker101 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
90288a0ca2f4 httpd "httpd-foreground" 21 minutes ago Up 21 minutes 0.0.0.0:80->80/tcp web
# 도커 이미지로 저장
[root@docker101 html]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
90288a0ca2f4 httpd "httpd-foreground" 45 minutes ago Up 45 minutes 0.0.0.0:80->80/tcp web
[root@docker101 html]# docker commit web webserver:v1
sha256:da5abb3ac3d357fdca71bfe1e923cab0fc5ed9dcc343aa6112e2597a30536d0d
[root@docker101 html]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
webserver v1 da5abb3ac3d3 12 seconds ago 178MB
# Tag link 생성
[root@docker101 html]# docker tag debian:latest devian:v1
[root@docker101 html]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
webserver v1 da5abb3ac3d3 About a minute ago 178M
devian v1 3bbb526d2608 3 weeks ago 101MB
debian latest 3bbb526d2608 3 weeks ago 101MB
# 호스트와 격리된 container의 격리 해제
- host PID 를 사용하여 컨테이너 시작
[root@docker101 ~]# docker run -it --pid=host ubuntu
root@d86a19e21469:/# ps
PID TTY TIME CMD
12581 pts/0 00:00:00 bash
14846 pts/0 00:00:00 bash
14889 pts/0 00:00:00 ps
[root@docker101 ~]# ps -ef | grep 12581
root 12581 12578 0 01:06 pts/0 00:00:00 -bash
root 14890 12581 0 02:14 pts/0 00:00:00 ps -ef
-- host에서 컨테이너의 프로세스 ID 확인
[root@docker101 ~]# docker inspect 7ebe136199ba | grep Pid
"Pid": 14347,
[root@docker101 ~]# ps -ef | grep 14347
root 14347 14332 0 02:09 pts/0 00:00:00 sh
root 14485 12581 0 02:10 pts/0 00:00:00 grep --color=auto 14347
-- 격리된 컨테이너에서 호스트의 네임스페이스 사용 (hostname )
[root@docker101 ~]# docker run -it ubuntu
root@8ed1084f0289:/# hostname
8ed1084f0289
[root@docker101 ~]# docker run -it --uts=host ubuntu
root@docker101:/# hostname
docker101.example.com
# runtime mode
-- background mode로 실행
[root@docker101 ~]# docker run -d ubuntu /bin/sh -c "while true; do date; done; sleep 2; done"
e4e9033fa62fba4a7e313842914d8360f0d03daa3282f9426f154bb9d23c3449
[root@docker101 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e4e9033fa62f ubuntu "/bin/sh -c 'while t…" 23 seconds ago Up 21 seconds keen_poincare
90288a0ca2f4 httpd "httpd-foreground" About an hour ago Up About an hour 0.0.0.0:80->80/tcp web
[root@docker101 ~]# docker logs e4e9033fa62f
Tue Aug 7 17:16:49 UTC 2018
Tue Aug 7 17:16:49 UTC 2018
Tue Aug 7 17:16:49 UTC 2018
.....
[root@docker101 ~]# docker run -itd ubuntu
cb2f5321460d32613d312bb373ed714c91e1e5a5b717244a536e633cfc5ea28c
[root@docker101 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cb2f5321460d ubuntu "/bin/bash" 2 seconds ago Up 1 second condescending_jackson
90288a0ca2f4 httpd "httpd-foreground" About an hour ago Up About an hour 0.0.0.0:80->80/tcp web
[root@docker101 ~]# docker attach cb2f5321460d
[root@docker101 ~]# docker start -aid 8ed1084f0289
ctl p q 입력
# 컨테이너 이미지를 인터렉티브하게 실행
[root@docker101 ~]# docker run -it fedora /bin/bash
Unable to find image 'fedora:latest' locally
latest: Pulling from library/fedora
e71c36a80ba9: Pull complete
Digest: sha256:7ae08e5637170eb47c01e315b6e64e0d48c6200d2942c695d0bee61b38c65b39
Status: Downloaded newer image for fedora:latest
- rm 옵션으로 컨테이너 종료 시 메모리에서 제거 함.
[root@docker101 ~]# docker run -it --rm --name test1 ubuntu
root@4827363965d2:/# exit
exit
[root@docker101 ~]# docker ps -a | grep test1
컨테이너 삭제 됨
-- 컨테이너 일괄 삭제
[root@8966d567038a /]# docker rm -f $(docker ps -aq)
# 컨테이너에서 호스트로 파일 copy
[root@docker101 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8ed1084f0289 ubuntu "/bin/bash" 3 hours ago Up 2 hours hopeful_wescoff
90288a0ca2f4 httpd "httpd-foreground" 4 hours ago Up 4 hours 0.0.0.0:80->80/tcp web
[root@docker101 ~]# docker cp 8ed1084f0289:/etc/passwd .
[root@docker101 ~]# ls passwd
passwd
컨테이너 별로 모니터링
[root@docker105 build3]# docker stats registry
CONTAINER
ID NAME CPU % MEM USAGE / LIMIT
MEM % NET I/O BLOCK I/O PIDS
c17726580ae9
registry 0.00% 3.484MiB / 1.796GiB
0.19% 48.4MB / 146kB 69.1MB / 81.8MB 7
현재 기동중인 프로세스
[root@docker101 dir1]# docker top webserver
UID
PID PPID C
STIME TTY TIME CMD
root
1905 1887 0
05:22 ? 00:00:00 httpd
-DFOREGROUND
bin 1942
1905 0 05:22
? 00:00:00 httpd -DFOREGROUND
bin
1943 1905 0
05:22 ? 00:00:00 httpd
-DFOREGROUND
bin 1944
1905 0 05:22
? 00:00:00 httpd -DFOREGROUND
# 실행중인 컨테이너에 명령 실행
[root@docker101 dir1]# docker ps
CONTAINER ID
IMAGE COMMAND CREATED
STATUS PORTS NAMES
3b3d885edcc1
ubuntu "/bin/bash" 29 seconds ago Up 28
seconds sleepy_volhard
[root@docker101 dir1]# docker exec 3b3d885edcc1 cat /etc/hosts
127.0.0.1 localhost
[root@docker101 dir1]# docker exec 3b3d885edcc1 vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
7 0 48 321652 2108 1217704 0 0 3 13 61 116 0 0 100 0 0
0 0 48 324360 2108 1217704 0 0 0 0 154 300 0 1 100 0 0
0 0 48 324464 2108 1217752 0 0 0 0 126 169 0 0 100 0 0
0 0 48 324464 2108 1217752 0 0 0 0 128 180 0 0 100 0 0
호스트에서도 80 포트로 확인 가능
# 컨테이너 이벤트
[root@docker101 ~]# docker stop 3b3d885edcc1
- 다른세션으로 events 명령을 통해 액션 로그 확인 가능
[root@docker101 dir1]# docker events
2018-08-08T08:17:44.025431145+09:00 container kill 3b3d885edcc1dcdca7cd5ec65f34386a2ca24af73d4bd487508d66e183742ddd (image=ubuntu, name=sleepy_volhard, signal=15)
2018-08-08T08:17:54.040524313+09:00 container kill 3b3d885edcc1dcdca7cd5ec65f34386a2ca24af73d4bd487508d66e183742ddd (image=ubuntu, name=sleepy_volhard, signal=9)
2018-08-08T08:17:54.075219996+09:00 container exec_die 3b3d885edcc1dcdca7cd5ec65f34386a2ca24af73d4bd487508d66e183742ddd (execID=5464c939cbfb5fe7329e303047115785ec19888a56e476108e49f5e368a59449, exitCode=137, image=ubuntu, name=sleepy_volhard)
2018-08-08T08:17:54.156535057+09:00 container die 3b3d885edcc1dcdca7cd5ec65f34386a2ca24af73d4bd487508d66e183742ddd (exitCode=137, image=ubuntu, name=sleepy_volhard)
2018-08-08T08:17:54.338161210+09:00 network disconnect 57d3e396b66ca705e1364fad465816fb5d1f8ce627cc12c749f7000be31a9d17 (container=3b3d885edcc1dcdca7cd5ec65f34386a2ca24af73d4bd487508d66e183742ddd, name=bridge, type=bridge)
2018-08-08T08:17:54.420927195+09:00 container stop 3b3d885edcc1dcdca7cd5ec65f34386a2ca24af73d4bd487508d66e183742ddd (image=ubuntu, name=sleepy_volhard)
# cAdvisor 설치 - 컨테이너 성능 수집
[root@docker101 ~]# docker run \
> --detach=true \
> --volume=/:/rootfs:ro \
> --volume=/var/run:/var/run:rw \
> --volume=/sys:/sys:ro \
> --volume=/var/lib/docker/:/var/lib/docker:ro \
> --publish=8080:8080 \
> --privileged=true \
> --name=cadvisor \
> google/cadvisor:latest
Unable to find image 'google/cadvisor:latest' locally |
http://docker101.example.com:8080/containers/
실습-container storage (0) | 2018.08.09 |
---|
댓글 영역