DevOps/Docker

Docker ๊ธฐ๋ณธ ๋ช…๋ น์–ด, ์‚ฌ์šฉ๋ฒ•

meeeeejin 2021. 4. 9. 00:28

Docker ๊ธฐ๋ณธ ๋ช…๋ น์–ด

 

Contaniner ์‹œ์ž‘ํ•˜๊ธฐ(Run)
docker run -it -d ${IMAGE_ID}	# -it: ํ„ฐ๋ฏธ๋„ ์ž…๋ ฅ์„ ์œ„ํ•œ ์˜ต์…˜; -d: detached mode
docker run --name ${CONTAINER_NAME} -it -d ${IMAGE_ID}	# --name: ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„ ์„ค์ • ์˜ต์…˜
cocker ps	# ์‹คํ–‰์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ ๋ชฉ๋ก ํ™•์ธ
docker ps -a	# ๋ชจ๋“  ์ปจํ…Œ์ด๋„ˆ ๋ชฉ๋ก ํ™•์ธ

 

 

Container ๋ช…๋ น์–ด ์‹คํ–‰ํ•˜๊ธฐ(Exec)
# ์‹คํ–‰์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ์— ๋ช…๋ น ๋‚ด๋ฆฌ๊ธฐ
docker exec -it [OPTIONS] ${CONTAINER_ID} ${COMMAND} [ARG...]
docker exec -it ubuntu bash		# ubuntu๋ผ๋Š” ์ด๋ฆ„์˜ ์ปจํ…Œ์ด๋„ˆ์— bash์‰˜๋กœ ์ ‘์†ํ•˜๋Š” ๋ช…๋ น์–ด
exit	# ์ปจํ…Œ์ด๋„ˆ ๋‚ด์—์„œ ์‹คํ–‰์ค‘์ธ ํ”„๋กœ๊ทธ๋žจ ๋‚˜๊ฐ€๊ธฐ(e.g. bash)

 

 

Container ์ค‘์ง€ํ•˜๊ธฐ(Stop)
docker stop [OPTIONS] ${CONTAINER_ID} [CONTAINER_ID...]
docker stop ubuntu	# ubuntu๋ผ๋Š” ์ด๋ฆ„์˜ ์ปจํ…Œ์ด๋„ˆ ์ค‘์ง€
docker ps -a		# ์ค‘์ง€๋œ ์ปจํ…Œ์ด๋„ˆ ํ™•์ธ

 

 

Container ์ œ๊ฑฐํ•˜๊ธฐ(Remove)
docker rm [OPTIONS] ${CONTAINER_ID} [CONTAINER_ID...]

docker rm ubuntu	# ubuntu๋ผ๋Š” ์ด๋ฆ„์˜ ์ปจํ…Œ์ด๋„ˆ ์‚ญ์ œ(์ปจํ…Œ์ด๋„ˆ๋Š” ์ค‘์ง€ ์ƒํƒœ์—ฌ์•ผ ํ•จ)
codker rm -f ${CONTAINER_ID}	# ์‹คํ–‰์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ค‘์ง€์‹œํ‚จ ํ›„ ์‚ญ์ œ

 

 

Image ๋‹ค์šด๋กœ๋“œํ•˜๊ธฐ(Pull)
docker pull [OPTIONS] NAME[:TAG|@DIGEST]

docker pull ubuntu:14.04	# ubuntu 14.04 ํƒœ๊ทธ์˜ ์ด๋ฏธ์ง€ ๋‹ค์šด๋กœ๋“œ
docker pull ubuntu			# ์ตœ์‹  ํƒœ๊ทธ์˜ ubuntu ๋‹ค์šด๋กœ๋“œ

docker images		# ์ด๋ฏธ์ง€ ๋ชฉ๋ก ํ™•์ธ

 

 

Image ์‚ญ์ œํ•˜๊ธฐ(Rmove Image)
docker rmi [OPTIONS] ${IMAGE_ID} [IMAGE...]

docker rmi ${IMAGE_ID}	# ์ด๋ฏธ์ง€ ์‚ญ์ œํ•˜๊ธฐ
docker images		# ์ด๋ฏธ์ง€ ๋ชฉ๋ก ํ™•์ธ

 

 

Dockerfile๋กœ Image ์ƒ์„ฑํ•˜๊ธฐ(Build)
docker build . -t ${IMAGE_NAME}		# .: ํ˜„์žฌ ๊ฒฝ๋กœ์˜ dockerfile๋กœ ์ด๋ฏธ์ง€ build

docker build . -t apache-server		# ํ˜„์žฌ ๊ฒฝ๋กœ์˜ dockerfile๋กœ apche-server๋ผ๋Š” ์ด๋ฏธ์ง€ ์ƒ์„ฑ

 

 

 

 

728x90

'DevOps > Docker' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Docker(๋„์ปค)๋ž€? Docker ๊ธฐ๋ณธ ๊ฐœ๋…  (0) 2021.03.29