์„ค์น˜

brew install docker

mac ์šฉ ๋„์ปค ์„ค์น˜ํ•˜๊ธฐ

Docker image download

docker pull hugojuhel/notebook
  • Docker Hub ์—์„œ ์›ํ•˜๋Š” docker ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด๋กœ๋“œ
  • ํ˜น์€ ์•„๋ž˜ ์˜ˆ์ œ์™€ ๊ฐ™์ด ๋ช…๋ น์–ด๋กœ ๋‹ค์šด๋ฐ›์„ ์ˆ˜๋„ ์žˆ์Œ
  • ์‚ฌ์šฉํ•œ ์ด๋ฏธ์ง€

Docker image ํ™•์ธ

docker images

์„ค์น˜ํ•œ ์ด๋ฏธ์ง€๋“ค์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

Docker container ์ƒ์„ฑ ๋ฐ ์‹คํ–‰

docker run -it --name jpt -v /Users/Choiwansik/Documents/internship/image_processing/share:/home/jovyan/share -p 28888:8888 hugojuhel/notebook /bin/bash

์‚ฌ์šฉ์ž ์ƒํ™ฉ์— ๋งž๊ฒŒ ์˜ต์…˜ ๊ณจ๋ผ ์‚ฌ์šฉ

  • ๋ช…๋ น์–ด๋Š” ํ•ญ์ƒ root ๊ถŒํ•œ์œผ๋กœ ์‹คํ–‰ํ•œ๋‹ค.
  • -i(interactive), -t(Pseudo-try) ์˜ต์…˜ : ์‹คํ–‰๋œ Bash ์…ธ์— ์ž…๋ ฅ ๋ฐ ์ถœ๋ ฅ์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • -v, --volume ์˜ต์…˜ : host folder์™€ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋‹ค.

jupyter notebook ์‹คํ–‰

jupyter notebook --ip=0.0.0.0 --allow-root

์‹คํ–‰ํ•˜๊ฒŒ ๋˜๋ฉด, ์•„๊นŒ ์—ฐ๊ฒฐํ•ด ๋‘์—ˆ๋˜ ๋กœ์ปฌ ํฌํŠธ๋กœ ์ ‘์†ํ•  ๊ฒฝ์šฐ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

Docker ๋ช…๋ น์–ด

๋„์ปค ๋ช…๋ น์–ด Cheat Cheet์ด๋‹ค. ๋‚˜์ค‘์— ์ด๊ฑฐ๋งŒ ๋ณด๊ณ  ์‚ฌ์šฉํ•˜๋„๋ก ํ•˜์ž.

ํ”„๋กœ์„ธ์Šค ๋ณด๊ธฐ

sudo docker ps -a

-a ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜๋ฉด ์ •์ง€๋œ ์ปจํ…Œ์ด๋„ˆ๊นŒ์ง€ ๋ชจ๋‘ ์ถœ๋ ฅํ•˜๊ณ , ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋ฉด ์‹คํ–‰๋˜๊ณ  ์žˆ๋Š” ์ปจํ…Œ์ด๋„ˆ๋งŒ ์ถœ๋ ฅํ•œ๋‹ค.

์ปจํ…Œ์ด๋„ˆ ์‹œ์ž‘ํ•˜๊ธฐ

sudo docker container start hello

์ด๋ฆ„ ๋Œ€์‹  container_id๋ฅผ ์‚ฌ์šฉํ•ด๋„ ๋œ๋‹ค.

์ปจํ…Œ์ด๋„ˆ ์žฌ๋ถ€ํŒ…

sudo docker container restart hello

์šด์˜์ฒด์ œ ์žฌ๋ถ€ํŒ…๊ณผ ์œ ์‚ฌํ•˜๋‹ค.

์ปจํ…Œ์ด๋„ˆ ์ ‘์†ํ•˜๊ธฐ

sudo docker container attach hello

bash์—์„œ exit ํ˜น์€ Ctrl+D ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ •์ง€๋œ๋‹ค.

exec ๋ช…๋ น์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ ์™ธ๋ถ€์—์„œ ๋ช…๋ น ์‹คํ–‰ํ•˜๊ธฐ

ํ˜„์žฌ hello ์ปจํ…Œ์ด๋„ˆ์˜ bin/bash๋ฅผ ์‹คํ–‰ํ•œ ์ƒํƒœ๋ผ๊ณ  ๊ฐ€์ •ํ•˜์ž. ๊ทธ๋ฆฌ๊ณ  ํ•ด๋‹น ์ปจํ…Œ์ด๋„ˆ์— ์ ‘์†ํ•˜์ง€ ์•Š์€ ์ƒํƒœ๋กœ, hello ์ปจํ…Œ์ด๋„ˆ ์•ˆ์˜ ๋ช…๋ น์„ ์‹คํ–‰ํ•ด๋ณด์ž.

sudo docker container exec hello echo "Hello World"

docker container exec <์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„> <๋ช…๋ น> <๋งค๊ฐœ๋ณ€์ˆ˜> ํ˜•์‹์ด๋‹ค. ์ปจํ…Œ์ด๋„ˆ ๋Œ€์‹  ์ปจํ…Œ์ด๋„ˆ id๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด ๋ช…๋ น์–ด๋Š” ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์‹คํ–‰๋˜๊ณ  ์žˆ๋Š” ์ƒํƒœ์—์„œ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ์ •์ง€๋œ ์ƒํƒœ์—์„œ๋Š” ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค.

docker exec ๋ช…๋ น์€ ์ด๋ฏธ ์‹คํ–‰๋œ ์ปจํ…Œ์ด๋„ˆ์— apt-get, yum ๊ณผ ๊ฐ™์€ ๋ช…๋ น์œผ๋กœ ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•˜๊ฑฐ๋‚˜ ๊ฐ์ข… ๋ฐ๋ชฌ์„ ์‹คํ–‰ํ•  ๋•Œ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

์ปจํ…Œ์ด๋„ˆ ์ •์ง€ํ•˜๊ธฐ

sudo docker container stop hello

์ •์ง€ํ•œ ๊ฒฝ์šฐ ๋‹ค์‹œ attachํ•˜๊ณ  ์‹ถ์œผ๋ฉด startํ›„ ๊ฐ€๋Šฅํ•˜๋‹ค.

์ปจํ…Œ์ด๋„ˆ ์‚ญ์ œํ•˜๊ธฐ

sudo docker container rm hello

container ๋ช…๋ น์–ด๋ฅผ ์“ฐ์ง€ ์•Š์•„๋„๋˜์ง€๋งŒ ์ตœ์‹  ๋ฒ„์ „์—์„œ๋Š” ๊ถŒ์žฅํ•œ๋‹ค.

์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰ ์ƒํƒœ๋กœ ๋น ์ ธ๋‚˜์˜ค๊ธฐ

์ปจํ…Œ์ด๋„ˆ ์•ˆ์—์„œ ctrl+pq์„ ๋ˆ„๋ฅด๋ฉด ๋œ๋‹ค.

์ปจํ…Œ์ด๋„ˆ ๋‚ด ์‚ฌ์šฉ์ž ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋ชจ๋ฅผ ๋•Œ

docker container exec -u 0 -it jpt /bin/bash

-u๋Š” default user๋ผ password๋ฅผ ํ•„์š”๋กœ ํ•˜์ง€ ์•Š๋Š”๋‹ค.

์ด๋ฏธ์ง€ ์‚ญ์ œํ•˜๊ธฐ

sudo docker rmi ubuntu:latest

docker rmi <์ด๋ฏธ์ง€ ์ด๋ฆ„>:<ํƒœ๊ทธ> ํ˜•์‹์ด๋‹ค. ์ด๋ฏธ์ง€ ์ด๋ฆ„ ๋Œ€์‹  id๋ฅผ ์‚ฌ์šฉํ•ด๋„ ๋œ๋‹ค. ํƒœ๊ทธ๋ฅผ ์ฃผ๋Š” ์ด์œ ๋Š” ๊ฐ™์€ ์ด๋ฆ„ ์ธ ๊ฒฝ์šฐ ๋ชจ๋‘ ์‚ญ์ œ๋˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

์ •๋ฆฌ

|๋ช…๋ น|Code| |::----|:โ€”:| |๋ฒ„์ „ ํ™•์ธ| docker pull [์ด๋ฏธ์ง€ ๋ช…]| |๋‹ค์šด๋กœ๋“œ๋œ ์ด๋ฏธ์ง€ ๋ชฉ๋ก| docker create [์˜ต์…˜] [์ด๋ฏธ์ง€ ๋ช…]| |์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑ ๋ฐ ์‹คํ–‰| docker run \[์˜ต์…˜\] \[์ด๋ฏธ์ง€ ๋ช…\]| |์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰| docker start [์ปจํ…Œ์ด๋„ˆ ๋ช…]| |์ปจํ…Œ์ด๋„ˆ ์žฌ์‹คํ–‰| docker restart \[์ปจํ…Œ์ด๋„ˆ ๋ช…\]| |์ปจํ…Œ์ด๋„ˆ ์ ‘์†| docker attach [์ปจํ…Œ์ด๋„ˆ ๋ช…]| |์ปจํ…Œ์ด๋„ˆ ์ •์ง€| docker stop \[์ปจํ…Œ์ด๋„ˆ ๋ช…\]| |์‹คํ–‰์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ ๋ชฉ๋ก| docker ps| |์ •์ง€๋œ ์ปจํ…Œ์ด๋„ˆ ๋ชฉ๋ก| docker rename [๊ธฐ์กด ์ปจํ…Œ์ด๋„ˆ ๋ช…] [์ƒˆ๋กœ์šด ์ปจํ…Œ์ด๋„ˆ ๋ช…]| |์ปจํ…Œ์ด๋„ˆ ์‚ญ์ œ|$ docker rm [์ปจํ…Œ์ด๋„ˆ ๋ช…]|

Reference