[Docker] docker ๋ช…๋ น์–ด ์ •๋ฆฌ

๋กœ๊ทธ์ธ

  • docker login: ๋„์ปค ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธ
  • docker info | grep Username: ๋กœ๊ทธ์ธํ•œ ๊ณ„์ • ์กฐํšŒ

๋„์ปค ์ด๋ฏธ์ง€

  • docker images: ๋„์ปค ์ด๋ฏธ์ง€ ์ „์ฒด ์กฐํšŒ
  • docker pull {์ด๋ฏธ์ง€๋ช…}:{ํƒœ๊ทธ}: ์ด๋ฏธ์ง€ ๋‹ค์šด
  • docker build -t {์ด๋ฏธ์ง€๋ช…}:{ํƒœ๊ทธ} {๊ฒฝ๋กœ}: Dockerfile ์‹คํ–‰ ๋ฐ ์ด๋ฏธ๋ช…, ํƒœ๊ทธ ์„ค์ •

์ปจํ…Œ์ด๋„ˆ

  • docker run -it --name={์ด๋ฆ„} {์ด๋ฏธ์ง€๋ช…} bash: ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์„ {์ด๋ฆ„}์œผ๋กœ ์ง€์ •ํ•˜๊ณ  {์ด๋ฏธ์ง€๋ช…}์„ ์‹คํ–‰, bash๋ฅผ ํ†ตํ•ด ๋‚ด๋ถ€๋กœ ๋“ค์–ด๊ฐ€๊ฒ ๋‹ค.
  • docker run -d -p {์™ธ๋ถ€ํฌํŠธ}:{๋‚ด๋ถ€ํฌํŠธ} --name={์ด๋ฆ„} {์ด๋ฏธ์ง€๋ช…}: ํฌํŠธ ํฌ์›Œ๋”ฉํ•˜๋ฉฐ ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋กœ ์ปจํ…Œ์ด๋„ˆ ์‹ค
  • docker ps: ์‹คํ–‰์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ ์กฐํšŒ
  • docker ps -a: ์‹คํ–‰์ค‘์ด๊ฑฐ๋‚˜ exited ๋œ ์ปจํ…Œ์ด๋„ˆ ์กฐํšŒ
  • ctrl + p + q: bash๋กœ ๋“ค์–ด์™”๋˜ ์ปจํ…Œ์ด๋„ˆ์—์„œ ๋‚˜์˜ค๊ธฐ (exit์œผ๋กœ ๋‚˜์˜ค๋ฉด ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ฃฝ์–ด๋ฒ„๋ฆฐ๋‹ค)
  • docker inspect {์ปจํ…Œ์ด๋„ˆ๋ช…} | grep -i ipa: {์ปจํ…Œ์ด๋„ˆ๋ช…}์— ํ•ด๋‹นํ•˜๋Š” ip Address ์กฐํšŒ
  • docker cp {์˜ฎ๊ธธ ํŒŒ์ผ} {์ปจํ…Œ์ด๋„ˆ๋ช…}:{๊ฒฝ๋กœ}: VM ํ™˜๊ฒฝ์˜ {์˜ฎ๊ธธ ํŒŒ์ผ}์„ ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์˜ ํŠน์ • ๊ฒฝ๋กœ๋กœ ์นดํ”ผ (๋กœ์ปฌ์—์„œ VM์œผ๋กœ ์˜ฎ๊ธธ ๋• WinSCP ํˆด ๋งค์šฐ ํŽธ๋ฆฌ)
  • docker build -t {์ปจํ…Œ์ด๋„ˆ๋ช…}:{ํƒœ๊ทธ} {๊ฒฝ๋กœ}: Dockerfile ์‹คํ–‰ ๋ฐ ์ปจํ…Œ์ด๋„ˆ๋ช…, ํƒœ๊ทธ ์„ค์ •
  • docker stop {์ปจํ…Œ์ด๋„ˆID}: ์ปจํ…Œ์ด๋„ˆID์— ํ•ด๋‹นํ•˜๋Š” ์ปจํ…Œ์ด๋„ˆ stop
  • docker rm {์ปจํ…Œ์ด๋„ˆID}: ์ปจํ…Œ์ด๋„ˆID์— ํ•ด๋‹นํ•˜๋Š” ์ปจํ…Œ์ด๋„ˆ ์‚ญ์ œ
  • alias cexrm='docker rm $(docker ps --filter 'status=exited' -a -q)': ์ƒ๋Œ€๊ฐ€ exited์ธ ์ปจํ…Œ์ด๋„ˆ ์ „๋ถ€ ์‚ญ์ œํ•˜๋Š” ๋ช…๋ น์–ด๋ฅผ alias๋กœ ์ €์žฅ. ์ถ”ํ›„์— cexrm์„ ์น˜๋ฉด ์ฃฝ์–ด์žˆ๋Š” ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ „๋ถ€ ์‚ญ์ œ๋จ. ์ด ๋ช…๋ น์–ด๋ฅผ vi .bashrc์— ์ ์–ด๋†“๊ณ  ์‚ฌ์šฉํ•˜๋ฉด ์˜๊ตฌ์ ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  •