๐Ÿ“‚ Container & K8S/Docker

[Docker] ๋„์ปค ๋„คํŠธ์›Œํฌ์™€ ๋ช…๋ น์–ด

dhyuck 2021. 9. 30. 00:18
๋ฐ˜์‘ํ˜•

๋„์ปค ๋„คํŠธ์›Œํฌ ๋“œ๋ผ์ด๋ฒ„ ์ข…๋ฅ˜

  • bridge : ๋“œ๋ผ์ด๋ฒ„๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š๊ณ  createํ•˜๋ฉด ์ƒ๊ธฐ๋Š” ๊ธฐ๋ณธ ๋„คํŠธ์›Œํฌ ๋“œ๋ผ์ด๋ฒ„์ž…๋‹ˆ๋‹ค.

  • host : ํ˜ธ์ŠคํŠธ์˜ ๋„คํŠธ์›Œํฌ๋ฅผ ์ง์ ‘ ์‚ฌ์šฉํ•˜๋Š” ๋“œ๋ผ์ด๋ฒ„์ž…๋‹ˆ๋‹ค.

  • overlay : ์—ฌ๋Ÿฌ ํ˜ธ์ŠคํŠธ์— ๋ถ„์‚ฐ๋˜์–ด ์žˆ๋Š” ์ปจํ…Œ์ด๋„ˆ๊ฐ„ ๋„คํŠธ์›Œํฌ ๊ตฌ์ถ•ํ•ด์•ผ ํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  • macvlan : ์ปจํ…Œ์ด๋„ˆ์— MAC ์ฃผ์†Œ๋ฅผ ํ• ๋‹นํ•˜์—ฌ ๋„คํŠธ์›Œํฌ์—์„œ ๋ฌผ๋ฆฌ์  ์žฅ์น˜์ฒ˜๋Ÿผ ๋ณด์ด๊ฒŒํ•ฉ๋‹ˆ๋‹ค.

    ์ด๋Š” VM์„ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ํ•˜๊ฑฐ๋‚˜ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๊ณ ์œ ์˜ MAC ์ฃผ์†Œ๋ฅผ ๊ฐ€์ง„ ๋ฌผ๋ฆฌ์  ํ˜ธ์ŠคํŠธ์ฒ˜๋Ÿผ ๋ณด์ด๋„๋ก ๋งŒ๋“ค์–ด์•ผํ•  ๋•Œ ์‚ฌ์šฉ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ, ์„œ๋กœ ๋‹ค๋ฅธ macvlan ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋ฌถ์–ด์„œ VLAN์„ ๊ตฌ์„ฑ ํ•  ์ˆ˜์žˆ์Šต๋‹ˆ๋‹ค.

  • none : ๋ชจ๋“  ๋„คํŠธ์›Œํฌ๋ฅผ ๋น„ํ™œ์„ฑํ™”ํ•œ ์ƒํƒœ์ž…๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉ์ž ์ง€์ • ๋„คํŠธ์›Œํฌ ๋“œ๋ผ์ด๋ฒ„์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.


๋„์ปค ๋„คํŠธ์›Œํฌ ๋ช…๋ น์–ด

  • ๋„์ปค ๋„คํŠธ์›Œํฌ ์กฐํšŒ (docker network ls)

      docker network ls [OPTIONS]
      # List networks
      # -f, --filter filter  ex) 'driver=bridge'
    
      # ex) driver๊ฐ€ bridge์ธ ๋„คํŠธ์›Œํฌ ์กฐํšŒ 
      docker network ls -f driver=bridge 
  • ๋„์ปค ๋„คํŠธ์›Œํฌ ์ƒ์„ฑ (docker network create)

      docker network create [OPTIONS] NETWORK
      # Create a network
      # -d, --driver string : ๋“œ๋ผ์ด๋ฒ„๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ๋ณธ ๋“œ๋ผ์ด๋ฒ„๋Š” ๋ธŒ๋ฆฟ์ง€
    
      # ex) my-net ๋ธŒ๋ฆฟ์ง€ ๋„คํŠธ์›Œํฌ ์ƒ์„ฑ
      docker network create my-net
  • ๋„์ปค ๋„คํŠธ์›Œํฌ ์—ฐ๊ฒฐ (docker network connect)

    ๊ตฌ๋™ ์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ์— connect ํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑ์‹œ ์—ฐ๊ฒฐ๋œ ๊ธฐ์กด ๋„คํŠธ์›Œํฌ๋Š” ์œ ์ง€๋˜๊ณ  ์ƒˆ๋กœ์šด ๋„คํŠธ์›Œํฌ๊ฐ€ ์ถ”๊ฐ€๋˜๋Š” ๊ฒƒ์œผ๋กœ, ์ด๋Š” ํ†ต์‹  ๊ฐ€๋Šฅํ•œ ๋„คํŠธ์›Œํฌ ๋Œ€์—ญ์ด ์ถ”๊ฐ€๋˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

    ๋งŒ์•ฝ ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑ์‹œ ๊ธฐ๋ณธ ๋„คํŠธ์›Œํฌ๋ฅผ ์„ค์ •ํ•˜๊ณ ์ž ํ•œ๋‹ค๋ฉด, run ํ•  ๋•Œ โ€”-network ์˜ต์…˜์„ ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

      docker network connect [OPTIONS] NETWORK CONTAINER
      # Connect a container to a network
      # --ip : ip4์ฃผ์†Œ ์ง€์ •
    
      # ex) ์‹คํ–‰์ค‘์ธ container1์„ my-net ๋„คํŠธ์›Œํฌ์— ์—ฐ๊ฒฐ
      docker network connect my-net container1
      # ex) ์ปจํ…Œ์ด๋„ˆ๋ฅผ run ํ•  ๋•Œ ๋„คํŠธ์›Œํฌ ์ง€์ •
      docker run --network=<network-name>
  • ๋„์ปค ๋„คํŠธ์›Œํฌ ์—ฐ๊ฒฐ ํ•ด์ œ (docker network disconnect)

      docker network disconnect [OPTIONS] NETWORK CONTAINER
      # Disconnect a container from a network
      # -f, --force : Force the container to disconnect from a network
    
      # ex) my-net ๋„คํŠธ์›Œํฌ์—์„œ container1 ๋„คํŠธ์›Œํฌ๋ฅผ ๋ถ„๋ฆฌ
      docker network disconnect my-net container1
  • ๋„์ปค ๋„คํŠธ์›Œํฌ ์ •๋ณด ํ™•์ธ (docker network inspect)

      docker network inspect [OPTIONS] NETWORK [NETWORK...]
      # Display detailed information on one or more networks
      # -f, --format string : Go ํ…œํ”Œ๋ฆฟ์„ ์‚ฌ์šฉํ•˜์—ฌ 
    
      # ex) my-net ๋„คํŠธ์›Œํฌ ์ •๋ณด ์ถœ๋ ฅ
      docker network inspect my-net
  • ๋„์ปค ๋„คํŠธ์›Œํฌ ์‚ญ์ œ(docker network rm)

      docker network rm NETWORK [NETWORK...]
      # Remove one or more networks
    
      # ex) my-net ๋„คํŠธ์›Œํฌ ์‚ญ์ œ
      docker network rm my-net
๋ฐ˜์‘ํ˜•