Skip to content

Latest commit

ย 

History

History
55 lines (49 loc) ยท 4.22 KB

docker_cmd.md

File metadata and controls

55 lines (49 loc) ยท 4.22 KB

Docker ๋ช…๋ น์–ด ์ •๋ฆฌ

Docker๋กœ ๋ฐฐํฌ๋œ DIF Universal Resolver๋ฅผ ์ ‘ํ•˜๋ฉด์„œ ์•Œ๊ฒŒ๋œ ๋ช…๋ น์–ด๋ฅผ ์ •๋ฆฌํ•œ๋‹ค๐Ÿ“

Docker ๋ช…๋ น์–ด

1. image

  • docker build -f <directory_dockerfile> -t <image_name> : image_name์œผ๋กœ directory_dockerfile์— ์žˆ๋Š” dockerfile๋กœ ๋นŒ๋“œ(images ์ƒ์„ฑ)
  • docker images : docker images ์กฐํšŒ
  • docker tag <already_created_image_name:tag> <new_image_Name>:tag : ๊ธฐ์กด ์ด๋ฏธ์ง€์— ๋Œ€ํ•ด ์ƒˆ๋กœ์šด ํƒœ๊ทธ ์ถ”๊ฐ€ํ•˜์—ฌ ์ƒ์„ฑ
  • docker image rm <image_name> : image_name์— ํ•ด๋‹นํ•˜๋Š” image ์‚ญ์ œ
  • docker rmi $(docker images -q) : ๋ชจ๋“  docker image ์‚ญ์ œ

2. container

  • docker container ls -a : ๋ชจ๋“  container ์กฐํšŒ
  • docker container rm <container_name> : container_name์— ํ•ด๋‹นํ•˜๋Š” ํŠน์ • container ์‚ญ์ œ
  • docker container stop <container_name> : container_name์— ํ•ด๋‹นํ•˜๋Š” ํŠน์ • container ์ค‘์ง€
  • docker container start <container_name> : (container_name์— ํ•ด๋‹นํ•˜๋Š”)์ค‘์ง€๋œ container๋ฅผ ์‹œ์ž‘
  • docker container restart <container_name> : (container_name์— ํ•ด๋‹นํ•˜๋Š”) container๋ฅผ ์žฌ์‹œ์ž‘
  • docker ps : docker ํ”„๋กœ์„ธ์Šค ์ถœ๋ ฅ
  • docker logs <container_name> : ํŠน์ • container์— ๋Œ€ํ•œ ๋กœ๊ทธ ์ถœ๋ ฅ
  • docker logs --tail <num> <container_name> : ํŠน์ • container์— ๋Œ€ํ•œ ๋กœ๊ทธ ์ค‘ ๋งˆ์ง€๋ง‰ n๋ฒˆ์งธ ์ค„ ์„ ํƒํ•˜์—ฌ ์ถœ๋ ฅ
  • docker logs --since <unix_timestampe> <container_name> : ํŠน์ • container์— ๋Œ€ํ•œ ๋กœ๊ทธ๋ฅผ ์œ ๋‹‰์Šคํƒ€์ž„์œผ๋กœ ํŠน์ • ์‹œ๊ฐ„์ดํ›„ ๋กœ๊ทธ ์ถœ๋ ฅ ๊ฐ€๋Šฅ
  • docker logs -f -t <container_name> : -f ์˜ต์…˜์œผ๋กœ ์‹ค์‹œ๊ฐ„ ๋กœ๊ทธ ํ™•์ธ๊ฐ€๋Šฅํ•˜๊ณ , -t๋Š” timestamp์™€ ํ•จ๊ป˜ ๋กœ๊ทธ ์ถœ๋ ฅ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•จ
    • /var/lib/docker/containers/${CONTAINER_ID}/${CONTAINER_ID}-json.log : ํ•ด๋‹น ๊ฒฝ๋กœ๋กœ json ํ˜•ํƒœ๋กœ docker ๋‚ด๋ถ€์— ์ €์žฅ๋จ
  • docker container prune : stop๋œ docker container ์‚ญ์ œ
  • docker stop $(docker ps -a -q) : ๋ชจ๋“  container stop

3. network

  • docker network ls : docker network ์กฐํšŒ
  • docker network create <network_name> : network_name์œผ๋กœ ๋„คํŠธ์›Œํฌ ์ƒ์„ฑ
    • ํŠน์ง•
      • default ๊ฐ’์€ "bridge" ๋“œ๋ผ์ด๋ฒ„๋กœ ์„ธํŒ…๋จ
      • ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๋™์ผํ•œ ๋„คํŠธ์›Œํฌ์— ์žˆ๋Š” ๊ฒฝ์šฐ, ์ด๋ฆ„์œผ๋กœ ์„œ๋กœ๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ์Œ
    • ์˜ต์…˜
      • docker network create --driver <driver> <network_name> : ํŠน์ • ๋“œ๋ผ์ด๋ฒ„๋กœ ์„ค์ •ํ•˜์—ฌ ๋„คํŠธ์›Œํฌ ์ƒ์„ฑ
        • bridge : ํ•˜๋‚˜์˜ ํ˜ธ์ŠคํŠธ ์ปดํ“จํ„ฐ ๋‚ด์—์„œ ์—ฌ๋Ÿฌ ์ปจํ…Œ์ด๋„ˆ๋“ค์ด ์„œ๋กœ ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์คŒ.
        • host : ํ˜ธ์ŠคํŠธ ๋„คํŠธ์›Œํฌ ํ™˜๊ฒฝ์„ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ. ๋‚ด๋ถ€ IP ํ• ๋‹นํ•„์š”์—†์ด ๊ณง๋ฐ”๋กœ ์‚ฌ์šฉ. ์ฆ‰ ํ˜ธ์ŠคํŠธ ์ปดํ“จํ„ฐ์™€ ๋™์ผํ•œ ๋„คํŠธ์›Œํฌ์—์„œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ ์‹œํ‚ค๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋จ.
        • overlay : ์—ฌ๋Ÿฌ docker ๋ฐ๋ชฌ์ด ์„œ๋กœ ์—ฐ๊ฒฐ๋  ์ˆ˜ ์žˆ์Œ. ์—ฌ๋Ÿฌ ํ˜ธ์ŠคํŠธ์— ๋ถ„์‚ฐ๋˜์–ด ๋Œ์•„๊ฐ€๋Š” ์ปจํ…Œ์ด๋„ˆ๋“ค ๊ฐ„์— ๋„คํŠธ์›Œํ‚น์„ ์œ„ํ•ด ์‚ฌ์šฉ๋จ.
        • none : ์•„๋ฌด๋Ÿฐ ๋„คํŠธ์›Œํฌ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์œผ๋กœ, ์™ธ๋ถ€์™€ ํ†ต์‹ ํ•˜์ง€ ์•Š์„ ๋•Œ ์‚ฌ์šฉํ•จ.
  • docker network insepct <network_name> : network_name์— ํ•ด๋‹นํ•˜๋Š” ๋„คํŠธ์›Œํฌ์˜ ์ƒ์„ธ ์ •๋ณด๋ฅผ ์ถœ๋ ฅ
  • docker network disconnect <driver> <container_name> : ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํŠน์ • ๋„คํŠธ์›Œํฌ๋กœ๋ถ€ํ„ฐ ์—ฐ๊ฒฐ ํ•ด์ œ
  • docker network rm <network_name> : network_name์— ํ•ด๋‹นํ•˜๋Š” ๋„คํŠธ์›Œํฌ ์‚ญ์ œ
  • docker network prune : ์•„๋ฌด ์ปจํ…Œ์ด๋„ˆ์™€ ์—ฐ๊ฒฐ๋˜์ง€ ์•Š์€ (์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”) ๋„คํŠธ์›Œํฌ๋ฅผ ํ•œ๋ฒˆ์— ๋ชจ๋‘ ์‚ญ์ œ

Docker compose ๋ช…๋ น์–ด

  • docker-compose --version : ๋ฒ„์ „ ํ™•์ธ(์ถœ๋ ฅ)
  • docker-compose -f docker-compose.yml pull : ์‹คํ–‰์ „ ์ด๋ฏธ์ง€/์ €์žฅ์†Œ ๊ฐ€์ ธ์˜ค๊ธฐ
  • docker-compose -f docker-compose.yml up : docker-compose.yml์„ ๋ฐ”ํƒ•์œผ๋กœ ์—ฌ๋Ÿฌ๊ฐœ์˜ container๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์‹œ์ž‘
  • docker-compose -f docker-compose.yml up -d : ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋กœ ์‹คํ–‰
  • docker-compose stop : ํ˜„์žฌ ๋””๋ ‰ํ„ฐ๋ฆฌ์— ์žˆ๋Š” docker-compose๋ฅผ ํ†ตํ•ด ๊ตฌ๋™ํ•œ ์„œ๋น„์Šค ์ค‘์ง€
  • docker-compose down : ํ˜„์žฌ ๋””๋ ‰ํ„ฐ๋ฆฌ์— ์žˆ๋Š” docker-compose๋ฅผ ํ†ตํ•ด ๊ตฌ๋™ํ•œ ์„œ๋น„์Šค ์ค‘์ง€ & ๊ตฌ๋™์‹œ ์‚ฌ์šฉ๋œ ์ปจํ…Œ์ด๋„ˆ ์ œ๊ฑฐ(์ดˆ๊ธฐํ™”์‹œํ‚ด)

์ฐธ๊ณ