1. Registry에서 pull로 이미지를 가져온다.
2. 가져온 이미지를 Create하게 되면 Container가 생성된다.
3. Container를 start 하게 되면 메모리에 올라간다.
4. run은 pull, create, start 3개의 명령을 순차적으로 수행하며 만약 pull이 수행 됬을경우 create 단계부터 순차적으로 실행한다.
5. Image의 삭제는 RMI명령어를 통해 삭제하며, Container의 삭제는 RM, 프로세스 중지는 Stop이다.
6. 만약 run으로 계속 수행 하게 되면 컨테이너를 계속 생성하니 상황에 맞게 수행한다.
1. 이미지 가져오기
root@ljw:~# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
Digest: sha256:10b8cc432d56da8b61b070f4c7d2543a9ed17c2b23010b43af434fd40e2ca4aa
Status: Image is up to date for nginx:latest
docker.io/library/nginx:latest
2. 이미지 확인
root@ljw:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest f6d0b4767a6c 10 days ago 133MB
consol/tomcat-7.0 latest 7c34bafd1150 5 years ago 601MB
4. 컨테이너 생성
root@ljw:~# docker create -p 80:80 --name nx nginx
2d25f222de353a77480c339a0711af132696bbd50950fcb2c098d9d186f109dc
4. 컨테이너 확인 ( 주의할점 : ps는 실행된 컨테이너만 조회, 모든 컨테이너 조회시 -a 옵션 붙여주자)
root@ljw:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d687b940854c consol/tomcat-7.0 "/bin/sh -c /opt/tom…" 2 hours ago Up 2 hours 0.0.0.0:8080->8080/tcp, 8778/tcp tc
root@ljw:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2d25f222de35 nginx "/docker-entrypoint.…" About a minute ago Exited (0) 10 seconds ago nx
d687b940854c consol/tomcat-7.0 "/bin/sh -c /opt/tom…" 2 hours ago Up 2 hours 0.0.0.0:8080->8080/tcp, 8778/tcp tc
5. 컨테이너 시작 (CONTAINER ID or NAMES로 실행)
root@ljw:~# docker start nx
nx
root@ljw:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2d25f222de35 nginx "/docker-entrypoint.…" About a minute ago Up 5 seconds 0.0.0.0:80->80/tcp nx
d687b940854c consol/tomcat-7.0 "/bin/sh -c /opt/tom…" 2 hours ago Up 2 hours 0.0.0.0:8080->8080/tcp, 8778/tcp tc
root@ljw:~# docker stop nx
nx
root@ljw:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2d25f222de35 nginx "/docker-entrypoint.…" About a minute ago Exited (0) 10 seconds ago nx
d687b940854c consol/tomcat-7.0 "/bin/sh -c /opt/tom…" 2 hours ago Up 2 hours 0.0.0.0:8080->8080/tcp, 8778/tcp tc
root@ljw:~# docker start 2d25f222de35
2d25f222de35
6. 컨테이너 run으로 실행 및 확인 ( 포트 지정을 다르게 해주어야한다.)
root@ljw:~# docker run -d -p 81:81 --name nx1 nginx
26e1e3abffcc07fb74fe2cfddce2ba5c50704c2974df070b252aad7a231917b7
root@ljw:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26e1e3abffcc nginx "/docker-entrypoint.…" 6 seconds ago Up 4 seconds 80/tcp, 0.0.0.0:81->81/tcp nx1
2d25f222de35 nginx "/docker-entrypoint.…" 3 minutes ago Up About a minute 0.0.0.0:80->80/tcp nx
d687b940854c consol/tomcat-7.0 "/bin/sh -c /opt/tom…" 2 hours ago Up 2 hours 0.0.0.0:8080->8080/tcp, 8778/tcp tc
7. 컨테이너 중지
root@ljw:~# docker stop nx1
nx1
8. 컨테이너 실행중 삭제 했을 경우
root@ljw:~# docker rm nx1
Error response from daemon: You cannot remove a running container 26e1e3abffcc07fb74fe2cfddce2ba5c50704c2974df070b252aad7a231917b7. Stop the container before attempting removal or force remove
9. 컨테이너 삭제
root@ljw:~# docker rm nx1
nx1
10. 이미지 삭제
root@ljw:~# docker rmi nginx
Untagged: nginx:latest
Untagged: nginx@sha256:10b8cc432d56da8b61b070f4c7d2543a9ed17c2b23010b43af434fd40e2ca4aa
Deleted: sha256:f6d0b4767a6c466c178bf718f99bea0d3742b26679081e52dbf8e0c7c4c42d74
Deleted: sha256:4dfe71c4470c5920135f00af483556b09911b72547113512d36dc29bfc5f7445
Deleted: sha256:3c90a0917c79b758d74b7040f62d17a7680cd14077f734330b1994a2985283b8
Deleted: sha256:a1c538085c6f891424160d8db120ea093d4dda393e94cd4713e3fff3c82299b5
Deleted: sha256:a3ee2510dcf02c980d7aff635909612006fd1662084d6225e52e769b984abeb5
Deleted: sha256:cb42413394c4059335228c137fe884ff3ab8946a014014309676c25e3ac86864
11. run으로 모두 실행
root@ljw:~# docker run -d -p 3306:3306 mysql
Unable to find image 'mysql:latest' locally
latest: Pulling from library/mysql
a076a628af6f: Already exists
f6c208f3f991: Pull complete
88a9455a9165: Pull complete
406c9b8427c6: Pull complete
7c88599c0b25: Pull complete
25b5c6debdaf: Pull complete
43a5816f1617: Pull complete
1a8c919e89bf: Pull complete
9f3cf4bd1a07: Pull complete
80539cea118d: Pull complete
201b3cad54ce: Pull complete
944ba37e1c06: Pull complete
Digest: sha256:feada149cb8ff54eade1336da7c1d080c4a1c7ed82b5e320efb5beebed85ae8c
Status: Downloaded newer image for mysql:latest
07b2d783a7de56363da017b2c58c370cc1312dc13daadea3b10703fc30736cd3
root@ljw:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
07b2d783a7de mysql "docker-entrypoint.s…" 9 seconds ago Exited (1) 8 seconds ago determined_shamir
64161ef9cb03 nginx "/docker-entrypoint.…" 3 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp nx
d687b940854c consol/tomcat-7.0 "/bin/sh -c /opt/tom…" 2 hours ago Up 2 hours 0.0.0.0:8080->8080/tcp, 8778/tcp tc
'Docker' 카테고리의 다른 글
도커 이미지 다운 (0) | 2021.01.23 |
---|---|
도커 이미지 설치 톰캣 (0) | 2021.01.23 |
도커 설치(Ubuntu-20.04 LTS) (0) | 2021.01.23 |