๐Ÿ“‚ Container & K8S/Docker

[Docker] ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ๋ช…๋ น์–ด ์ •๋ฆฌ

dhyuck 2021. 8. 22. 22:36
๋ฐ˜์‘ํ˜•

  • ๋„์ปค ๋ฒ„์ „ ํ™•์ธ(docker version)

      docker version
      # Show the Docker version information
  • ๋„์ปค ์ƒ์„ธ์ •๋ณด ํ™•์ธ(docker inspect)

      docker inspect [OPTIONS] NAME|ID [NAME|ID...]
      # Return low-level information
  • ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑ ๋ฐ ์‹คํ–‰(docker container run)

      docker container run [OPTIONS] IMAGE [COMMAND] [ARG...]
      # Run a command in a new container
      # -d, --detach : ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋กœ ์‹คํ–‰ํ•˜๊ณ , ์ปจํ…Œ์ด๋„ˆ ID๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.
      # -p, --publish list : ํ˜ธ์ŠคํŠธ์˜ ํฌํŠธ์™€ ์ปจํ…Œ์ด๋„ˆ์˜ ํฌํŠธ๋ฅผ ๋ฐ”์ธ๋”ฉํ•ฉ๋‹ˆ๋‹ค. ํ˜ธ์ŠคํŠธ ํฌํŠธ:์ปจํ…Œ์ด๋„ˆ ํฌํŠธ
      # --name string : ์ปจํ…Œ์ด๋„ˆ์— ์ด๋ฆ„์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค.
    
      # ex) ์ตœ์‹  nginx ์ด๋ฏธ์ง€๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋„์›๋‹ˆ๋‹ค. ์ด๋ฆ„์€ test_nginx์ด๊ณ , ํ˜ธ์ŠคํŠธ 1234ํฌํŠธ์™€ ์ปจํ…Œ์ด๋„ˆ 80ํฌํŠธ๋ฅผ ๋ฐ”์ธ๋”ฉํ•ฉ๋‹ˆ๋‹ค.
      docker container run -d -p 1234:80 --name test_nginx nginx:latest
  • ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑ(docker container create)

      docker container create [OPTIONS] IMAGE [COMMAND] [ARG...]
      # Create a new container
  • ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰ ์ค‘๋‹จ(docker container stop)

      docker container stop [OPTIONS] CONTAINER [CONTAINER...]
      # Stop one or more running containers
  • ์ค‘๋‹จ๋œ ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰(docker container start)

      docker container start [OPTIONS] CONTAINER [CONTAINER...]
      # Start one or more stopped containers
  • ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ๋ฆฌ์ŠคํŠธ ํ™•์ธ(docker container ps)

      docker container ps [OPTIONS]
      # List containers
      # -a, --all : ๋ชจ๋“  ์ปจํ…Œ์ด๋„ˆ ์ถœ๋ ฅ, ๊ธฐ๋ณธ์€ ์‹คํ–‰ ์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ๋งŒ ์ถœ๋ ฅ
    
      # ex) ๋ชจ๋“  ์ปจํ…Œ์ด๋„ˆ ๋ฆฌ์ŠคํŠธ ์ถœ๋ ฅ
      docker container ps -a
  • ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ๋กœ๊ทธ ํ™•์ธ(docker container logs)

      docker container logs [OPTIONS] CONTAINER
      # Fetch the logs of a container
      # -f, --follow : Follow log output (์‹ค์‹œ๊ฐ„ ๋กœ๊ทธ ์ถœ๋ ฅ)
      # -t, --timestamps : ํƒ€์ž„์Šคํƒฌํ”„ ์ถœ๋ ฅ
    
      # ex) ์‹ค์‹œ๊ฐ„์œผ๋กœ ํƒ€์ž„์Šคํƒฌํ”„์™€ ํ•จ๊ป˜ test_nginx ๋กœ๊ทธ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค
      docker container logs -tf test_nginx
  • ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„ ๋ณ€๊ฒฝ(docker container rename)

      docker container rename CONTAINER NEW_NAME
      # Rename a container
  • ๋„์ปค ์ปจํ…Œ์ด๋„ˆ์—์„œ ํŒŒ์ผ ๋ณต์‚ฌ(docker container cp)

      docker container cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
      # Copy files/folders between a container and the local filesystem
    
      # ex) test_nginx ์ปจํ…Œ์ด๋„ˆ์˜ '/usr/share/nginx/html/index.html'๋ฅผ './TEST'๋กœ ๋ณต์‚ฌ
      docker container cp test_nginx:/usr/share/nginx/html/index.html ./TEST
    
      # ex) ํ˜„์žฌ ๋””๋ ‰ํ„ฐ๋ฆฌ์— ์žˆ๋Š” 'index.html'๋ฅผ test_nginx ์ปจํ…Œ์ด๋„ˆ์˜ '/usr/share/nginx/html/index.html'๋กœ ๋ณต์‚ฌ
      docker container cp index.html test_nginx:/usr/share/nginx/html/index.html
  • ๋„์ปค ์ปจํ…Œ์ด๋„ˆ์— ๋ช…๋ น(docker container exec)

      docker container exec [OPTIONS] CONTAINER COMMAND [ARG...]
      # Run a command in a running container
      # -i, --interactive : ํ‘œ์ค€ ์ž…์ถœ๋ ฅ ์—ฐ๊ฒฐ
      # -t, --tty : ๊ฐ€์ƒ์˜ ํ„ฐ๋ฏธ๋„ ํ• ๋‹น
    
      # ex) test_nginx ์ปจํ…Œ์ด๋„ˆ์— bash๋กœ ์‹คํ–‰ ์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ๋กœ ์ ‘์†
      docker container exec -it test_nginx bash
  • ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ๋ณ€๊ฒฝ์‚ฌํ•ญ ํ™•์ธ(docker container diff)

      docker container diff CONTAINER
      # Inspect changes to files or directories on a container's filesystem
  • ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ์‚ญ์ œ(docker container rm)

      docker container rm [OPTIONS] CONTAINER [CONTAINER...]
      # Remove one or more containers

๋ฐ˜์‘ํ˜•