์ด๋ฒํฌ์คํ ์์๋ ์ด๋ฏธ์ง์ ๋ํ ๊ธฐ๋ณธ ๋ด์ฉ์ ๋ค๋ฃจ๊ฒ ์ต๋๋ค.
์์ํ๊ธฐ์ ์, ๋ชจ๋ ๋์ปค ์ด๋ฏธ์ง์ ์ปจํ ์ด๋๋ฅผ ์ญ์ ํ๊ฒ ์ต๋๋ค. ํท๊ฐ๋ฆด์์์ผ๋๊น์!
๋จผ์ ์ปจํ ์ด๋ ์ ์ฒด ์ญ์ !
[root@docker-master /]# docker rm -f $(docker ps -aq)
2bf8c98f110d
๊ทธ๋ค์ ์ด๋ฏธ์ง๋ ๋ชจ๋ ์ญ์ ํ๊ฒ ์ต๋๋ค!
[root@docker-master /]# docker rmi -f $(docker images -q)
Untagged: registry:2
Untagged: registry@sha256:8be26f81ffea54106bae012c6f349df70f4d5e7e2ec01b143c46e2c03b9e551d
Deleted: sha256:2d4f4b5309b1e41b4f83ae59b44df6d673ef44433c734b14c1c103ebca82c116
Deleted: sha256:36a83751a1193f6edf65d21f62fe7988394d562d71904ee20cb4aa72f14148bd
Deleted: sha256:c2588dfa0db64031c1c0683ed59a00ad0943889efb819bffd0455ae9b232016c
Deleted: sha256:6eb97e254200a2d82064e63977f84626e376256fe4d4c033a8b7817b2950071d
Deleted: sha256:7c6634cc9948baef3600559e298228a962bd9499cbbaf840d4d4889f5abaca2a
Deleted: sha256:3e207b409db364b595ba862cdc12be96dcdad8e36c59a03b7b3b61c946a5741a
์ด๋ฒ ์ค์ต์์๋ Image์ ๋ํ ๋ด์ฉ์ ๋ค๋ฃฐ ์์ ์
๋๋ค.
๋ณธ๊ฒฉ์ ์ผ๋ก ์์ํ๊ธฐ ์ ์ Docker Folw์ ๊ฐ๋ตํ ์ดํด๋ณผ๊ฒ์ :)
1. Docker Image Pull : ์ด๋ฏธ์ง ๋ค์ด๋ก๋
docker pull ๋ช ๋ น์ด๋ก ์ฝ๊ฒ ๋์ปค ์ด๋ฏธ์ง๋ฅผ ์ธ๋ถ ์ ์ฅ์์์ ๋ค์ด๋ก๋ ํฉ๋๋ค.
[root@docker-master /]# docker pull centos/httpd-24-centos7
Using default tag: latest
latest: Pulling from centos/httpd-24-centos7
75f829a71a1c: Pull complete
e2c4942f4189: Pull complete
f1498894b11c: Pull complete
da56c9694723: Pull complete
063ff8a1435c: Pull complete
09351523c1de: Pull complete
9a03c4ed0deb: Pull complete
17f560ff6bfd: Pull complete
Digest: sha256:df111e9031b838fa9b5c120b07cba0f23188a539e9be91e020b0a9f77d65ec9e
Status: Downloaded newer image for centos/httpd-24-centos7:latest
docker.io/centos/httpd-24-centos7:latest
์ด๋ฏธ์ง๊ฐ ์ ์ ์ฅ๋์๋์ง ํ์ธํฉ๋๋ค.
[root@docker-master /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos/httpd-24-centos7 latest 24aec7b98d6b 3 days ago 344MB
2. Docker Image๋ก ์ปจํ ์ด๋ ์์ฑ ๋ฐ ํ์ธ
์์์ ๋ค์ด๋ฐ์ ์ด๋ฏธ์ง๋ก ์ปจํ ์ด๋๋ฅผ ์คํ์ํค๊ฒ ์ต๋๋ค.
[root@docker-master /]# docker run --name httpd -d -p 8180:8080 centos/httpd-24-centos7
dc1351b75b8d9f63e0444f2a5e74f7f08f55011a593abd4108d24cad74419494
์ ์คํ์ค์ธ์ง ํ์ธํฉ๋๋ค.
[root@docker-master /]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dc1351b75b8d centos/httpd-24-centos7 "container-entrypoin…" 5 seconds ago Up 4 seconds 8443/tcp, 0.0.0.0:8180->8080/tcp httpd
3. ์ปจํ ์ด๋๋ฅผ ์ด๋ฏธ์ง๋ก ์ ์ฅ : Docker Commit
commit ์ ์ปจํ
์ด๋๋ฅผ ์ด๋ฏธ์ง๋ก ์ ์ฅํ๋ ๋ช
๋ น์ด ์
๋๋ค. :)
์ด๋ฒ ๋จ๊ณ์์๋ ํ์ฌ ์คํ์ค์ธ ์ปจํ
์ด๋๋ฅผ ์์ ํ๊ณ , commit ํ์ฌ ์๋ก์ด ๋ฒ์ ์ ์ปจํ
์ด๋๋ฅผ ์์ฑํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
์, ์ปจํ ์ด๋ ๋ชฉ๋ก์ ํ์ธํ๊ณ ์์์ ์คํํ ์ปจํ ์ด๋์ ์ ์ํฉ๋๋ค.
[root@docker-master /]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dc1351b75b8d centos/httpd-24-centos7 "container-entrypoin…" 4 minutes ago Up 4 minutes 8443/tcp, 0.0.0.0:8180->8080/tcp httpd
[root@docker-master /]# docker container exec -it httpd /bin/bash
index.html ํ์ผ์ ์์ฑํฉ๋๋ค. :)
์ด์ , ์ด ์ปจํ
์ด๋๋ This is Docker Test ๋ผ๋ index.html์ ๋ฐํํ๊ฒ ๋ฉ๋๋ค.
bash-4.2$ echo 'This is Docker Test' > /var/www/html/index.html
bash-4.2$ exit
exit
์, ์ด์ ์ปจํ ์ด๋๋ฅผ ์ค์งํ๊ณ , ์ปค๋ฐํฉ๋๋ค.
* docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
-a = ์์ฑ์ ์ง์
-m = ๋ฉ์์ง ์ง์
[root@docker-master /]# docker container stop httpd
httpd
[root@docker-master /]# docker container commit -a 'mini' -m 'Add Index.html' httpd
sha256:d6422173cd696f5f2b3750cb7025d8962ea9a7ff493a55466b0058c1100884c4
์ด๋ฏธ์ง๋ฅผ ํ์ธํฉ๋๋ค. None ์ด๋ผ๋ ํ๊ทธ๋ฅผ ๊ฐ์ง ์ด๋ฏธ์ง๊ฐ ์์ฑ๋์๋ค์ :)
[root@docker-master /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> d6422173cd69 6 seconds ago 344MB
centos/httpd-24-centos7 latest 24aec7b98d6b 3 days ago 344MB
4. Docker Image ํ๊ทธ
์ด๋ฏธ์ง์ ํ๊ทธ๋ฅผ ๋ฌ์์ผ ํฉ๋๋ค.
[root@docker-master /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> d6422173cd69 6 seconds ago 344MB
centos/httpd-24-centos7 latest 24aec7b98d6b 3 days ago 344MB
docker image tag ๋ช ๋ น์ด๋ฅผ ํตํด ์ด๋ฏธ์ง์ ํ๊ทธ๋ฅผ ๋ฌ์์ค๋๋ค :)
* docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
์ดํ์ ์ด๋ฏธ์ง๋ฅผ ํ์ธํด๋ณด๋ฉด, ํ๊ทธ๊ฐ ์ ์์ ์ผ๋ก ์ค์ ๋๊ฒ์ ๋ณผ ์ ์์ต๋๋ค.
[root@docker-master /]# docker image tag 24aec7b98d6b 1mini2/myrepo:addIndex_v1
[root@docker-master /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
1mini2/myrepo addIndex_v1 24aec7b98d6b 3 days ago 344MB
centos/httpd-24-centos7 latest 24aec7b98d6b 3 days ago 344MB
5. Docker registry์ Push/Pull ํ๊ธฐ (๋์ปค ํ๋ธ ์ฌ์ฉ)
๋์ปค ํ๋ธ์ ์ ์ํ์๊ณ , ๋ ํฌ์งํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
์ด ๋จ๊ณ์์๋ ๋ณ๋๋ก ์๋ดํ์ง ์์ต๋๋ค :)
docker login ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ ๋์ปค ํ๋ธ์ ๋ก๊ทธ์ธ ํฉ๋๋ค.
[root@docker-master /]# docker login --username 1mini2
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
์ด์ , ์ด ์ด๋ฏธ์ง๋ฅผ ๋์ปค ํ๋ธ ๋ ํฌ์งํ ๋ฆฌ๋ก Pushํฉ๋๋ค.
[root@docker-master /]# docker image push 1mini2/myrepo:addIndex_v1
The push refers to repository [docker.io/1mini2/myrepo]
c6c197ea251d: Mounted from centos/httpd-24-centos7
be00ea727b88: Mounted from centos/httpd-24-centos7
4973b9e35e84: Mounted from centos/httpd-24-centos7
f4626fba958f: Mounted from centos/httpd-24-centos7
a317a6aa16e0: Mounted from centos/httpd-24-centos7
7da7d3716181: Mounted from centos/httpd-24-centos7
0b0618c6ced8: Mounted from centos/httpd-24-centos7
613be09ab3c0: Mounted from centos/httpd-24-centos7
๋์ปค ํ๋ธ ์ ์ ์ ์ ๋ก๋๋ ์ด๋ฏธ์ง ํ์ธ ๊ฐ๋ฅํฉ๋๋ค.
์ด์ ์ด ์ด๋ฏธ์ง๋ฅผ ๋ค์ด๋ก๋ ๋ฐ์๋ณด๊ฒ ์ต๋๋ค.
[root@docker-master /]# docker rmi -f $(docker images -q)
Untagged: 1mini2/myrepo:addIndex_v1
Untagged: 1mini2/myrepo@sha256:df111e9031b838fa9b5c120b07cba0f23188a539e9be91e020b0a9f77d65ec9e
Deleted: sha256:24aec7b98d6bc27d1a9af66958328cf4193c6f29b770b3005da1ae00baa13e61
๋์ปค ์ด๋ฏธ์ง ๋ชฉ๋ก์ ํ์ธํ๊ฒ ์ต๋๋ค. ์๋ฌด๊ฒ๋ ์์ต๋๋ค.
[root@docker-master /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker pull ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ ๋์ปค ํ๋ธ์ ์ ๋ก๋ํด๋์๋ ์ด๋ฏธ์ง๋ฅผ ๋ค์ด๋ฐ์ต๋๋ค.
[root@docker-master /]# docker pull 1mini2/myrepo:addIndex_v1
addIndex_v1: Pulling from 1mini2/myrepo
75f829a71a1c: Already exists
e2c4942f4189: Already exists
f1498894b11c: Already exists
da56c9694723: Already exists
063ff8a1435c: Already exists
09351523c1de: Already exists
9a03c4ed0deb: Already exists
17f560ff6bfd: Already exists
Digest: sha256:df111e9031b838fa9b5c120b07cba0f23188a539e9be91e020b0a9f77d65ec9e
Status: Downloaded newer image for 1mini2/myrepo:addIndex_v1
docker.io/1mini2/myrepo:addIndex_v1
๋์ปค ์ด๋ฏธ์ง๋ฅผ ํ์ธํฉ๋๋ค.
[root@docker-master /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
1mini2/myrepo addIndex_v1 24aec7b98d6b 3 days ago 344MB
6. Docker ์ด๋ฏธ์ง ์ ์ฅ(save) ๋ฐ ์ฌ์ฉ (load)
๋์ปค ์ปจํ ์ด๋๋ tarํ์ผ๋ก ์ ์ฅ์ด ๊ฐ๋ฅํ๋ฉฐ, ์ด๋ ๊ฒ tar๋ก ์ ์ฅํ์ฌ ๋ณด๊ดํ๊ณ ๋ค์ ๋ก๋ํ์ฌ ์ฌ์ฉํ ์ ์์ต๋๋ค.
ํท๊ฐ๋ฆฌ์ง ์๊ฒ ๋จผ์ ๋๋ ํฐ๋ฆฌ๋ฅผ ํ๋ ๋ง๋ค๊ณ ๊ทธ ์์์ ์์ ํ๋๋ก ํ๊ฒ ์ต๋๋ค.
[root@docker-master /]# mkdir /docker_images && cd docker_images/
๋์ปค ์ด๋ฏธ์ง ๋ชฉ๋ก์ ํ์ธํด๋ด ๋๋ค.
[root@docker-master docker_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
1mini2/myrepo addIndex_v1 24aec7b98d6b 3 days ago 344MB
๋์ปค ์ด๋ฏธ์ง๋ฅผ tarํ์ผ๋ก ์ ์ฅํฉ๋๋ค.
* ๋ช ๋ น์ด : docker save [OPTIONS] IMAGE [IMAGE...]
[root@docker-master docker_images]# docker save -o myweb.tar 1mini2/myrepo:addIndex_v1
์ ์ฅ์ด ์ ๋์๋์ง ํ์ธํฉ๋๋ค.
์ ์ ์ฅ ๋์๋ค์ :)
[root@docker-master docker_images]# ls -al
ํฉ๊ณ 348232
drwxr-xr-x. 2 root root 23 9์ 29 02:44 .
dr-xr-xr-x. 18 root root 262 9์ 29 02:44 ..
-rw-------. 1 root root 356587008 9์ 29 02:44 myweb.tar
์ ์ด์ ์ด tarํ์ผ์ ๋ค์ ์ด๋ฏธ์ง๋ก ๊ฐ์ ธ์ฌ ์์ ์ธ๋ฐ, ๊ทธ ์ค์ต์ ์งํํ๊ธฐ ์ ์!
๋์ปค ์ด๋ฏธ์ง๋ฅผ ์ ์ฒด ์ญ์ ํด์ค๋๋ค. ํท๊ฐ๋ฆด ์ ์์ผ๋๊น์.
[root@docker-master docker_images]# docker rmi -f $(docker images -q)
Untagged: 1mini2/myrepo:addIndex_v1
Untagged: 1mini2/myrepo@sha256:df111e9031b838fa9b5c120b07cba0f23188a539e9be91e020b0a9f77d65ec9e
Deleted: sha256:24aec7b98d6bc27d1a9af66958328cf4193c6f29b770b3005da1ae00baa13e61
[root@docker-master docker_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
์, ์ด์ docker load ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ tarํ์ผ์ ์ด๋ฏธ์ง๋ก ๋ก๋ํฉ๋๋ค.
[root@docker-master docker_images]# docker load -i ./myweb.tar
Loaded image: 1mini2/myrepo:addIndex_v1
์ ๋ก๋ ๋์๋์ง ํ์ธํด๋ด ๋๋ค.
[root@docker-master docker_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
1mini2/myrepo addIndex_v1 24aec7b98d6b 3 days ago 344MB
7. Docker ์ด๋ฏธ์ง & ์ปจํ ์ด๋ ์ญ์
๋ชจ๋ ํ
์คํธ๊ฐ ๋ง๋ฌด๋ฆฌ ๋์์ต๋๋ค :)
์ปจํ
์ด๋๋ฅผ ์ ๋ฆฌํด๋ด
์๋ค.๋์ปค ์ด๋ฏธ์ง์ ์ปจํ
์ด๋๋ฅผ ํ์ธํฉ๋๋ค.
[root@docker-master /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
1mini2/myrepo addIndex_v1 24aec7b98d6b 3 days ago 344MB
[root@docker-master /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dc1351b75b8d 24aec7b98d6b "container-entrypoin…" 28 minutes ago Exited (0) 23 minutes ago httpd
๋์ปค ์ด๋ฏธ์ง ์ ์ฒด ์ญ์ ๋ฅผ docker rmi -f $(docker images) ๋ช ๋ น์ด๋ฅผ ํตํด ์งํํฉ๋๋ค.
[root@docker-master /]# docker rmi -f $(docker images)
Untagged: 1mini2/myrepo:addIndex_v1
Deleted: sha256:24aec7b98d6bc27d1a9af66958328cf4193c6f29b770b3005da1ae00baa13e61
๋์ปค ์ปจํ ์ด๋ ์ ์ฒด ์ญ์ ๋ฅผ docker rm -f $(docker ps -aq) ๋ช ๋ น์ด๋ฅผ ํตํด ์งํํฉ๋๋ค.
[root@docker-master /]# docker rm -f $(docker ps -aq)
dc1351b75b8d
์ปจํ ์ด๋์ ์ด๋ฏธ์ง๊ฐ ์ ์ญ์ ๋์๋์ง ํ์ธํฉ๋๋ค :)
[root@docker-master /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@docker-master /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES