[docker] ๋„์ปค๐Ÿ‹ ์ฐจ๊ทผ์ฐจ๊ทผ ์•Œ์•„๋ณด๊ธฐ 2

์ด๋ฒˆ์—” ์•ž์„œ ํ•˜๋˜ ๋„์ปค ์ด๋ฏธ์ง€ ๋ง๊ณ  ๋‹ค๋ฅธ ์‹์œผ๋กœ ์‹œ๋„ํ•ด๋ณด์•˜๋‹ค. ์•ž์„œ ์‹œ๋„ํ•œ ๊ฒƒ์€, ํŒŒ์ผ๊นŒ์ง€ ์ž๋™์œผ๋กœ ๋Œ๋ฆด ์ˆ˜ ์žˆ๋Š” image ๋ฅผ ๋งŒ๋“ค์–ด์„œ run ๋ช…๋ น์–ด ํ•˜๋‚˜์— ๋๋‚ด๋Š” ๊ฒƒ์ด์—ˆ๋Š”๋ฐ, ์ƒ๊ฐ์„ ๋ฐ”๊พธ์–ด์„œ, ํ•„์š”ํ•œ docker ํ™˜๊ฒฝ์„ ์—ด๋ฉด ๊ทธ ์•ˆ์—์„œ ํ•„์š”ํ•œ ํŒŒ์ผ๋“ค์„ ์‹คํ–‰์‹œํ‚ค๋Š” ํ˜•์‹์œผ๋กœ ํ•˜๋„๋ก ํ•˜์˜€๋‹ค.

ํ•„์š”ํ•œ cuda image๋ฅผ pull ํ•ด์˜ค๊ณ , ๊ทธ pull ํ•ด์˜จ image ์— ๋‚ด๊ฐ€ ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์„ ์ถ”๊ฐ€๋กœ install ํ•˜์—ฌ ๋‚˜๋งŒ์˜ custum docker image ๋ฅผ ๋งŒ๋“ค์–ด์„œ, ๋ฐฐํฌ๊ฐ€ ๊ฐ€๋Šฅํ•˜๊ฒŒ docker hub ์— ์˜ฌ๋ฆฌ๋Š” ๊ฒƒ ๊นŒ์ง€ ํ•˜์˜€๋‹ค.

ํ˜น์‹œ ๋„์ปค ์„ค์น˜๋ถ€ํ„ฐ ํ•˜๊ณ ์‹ถ์€ ์‚ฌ๋žŒ์€ [docker] ๋„์ปค๐Ÿ‹ ์ฐจ๊ทผ์ฐจ๊ทผ ์•Œ์•„๋ณด๊ธฐ ์—ฌ๊ธฐ ์ฐธ๊ณ !

docker login

docker login

๋กœ๊ทธ์ธ ํ•˜์ž๋งˆ์ž sock permission deniedโ€ฆ

image

group ์— ๊ถŒํ•œ ์„ค์ •ํ•ด์ฃผ๋ฉด ๋œ๋‹ค. chomod 666์œผ๋กœ read write ๋“ฑ ๋‹ค ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•ด์ฃผ์ž

sudo chmod 666 /var/run/docker.sock

๋‹ค์‹œ ๋กœ๊ทธ์ธํ•˜๋‹ˆ ์„ฑ๊ณตํ•˜์˜€๋‹ค ํ˜ธํ˜ธ

image

## docker run

gpu ๋ฅผ ์‚ฌ์šฉํ•  ๊ฒƒ์ด๋ฏ€๋กœ โ€“gpus ํƒœ๊ทธ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ , all ์€ gpu๊ฐ€ ๋ช‡๊ฐœ๋˜ ๋‹ค ์ฝ์–ด์˜ค๊ฒ ๋‹ค๋Š” ๋œป์ด๋‹ค ๋งŒ์•ฝ 4๊ฐœ์ค‘ 0๋ฒˆ๊ณผ 1๋ฒˆ์งธ๊ฒƒ๋งŒ ๊ฐ€์ ธ์˜ค๊ณ  ์‹ถ๋‹ค๋ฉด โ€“gpus โ€˜โ€œdevices=0,1โ€โ€™ ์œผ๋กœ ์„ค์ •ํ•ด์ฃผ๋ฉด๋œ๋‹ค. -v ๋‹ค์Œ์— $(pwd)๋Š” ํ˜„์žฌ ์ž‘์—…์œ„์น˜๋ฅผ ๋œปํ•˜๊ณ  ๊ทธ ๋’ค์— ๋‚ด๊ฐ€ ์ ‘๊ทผํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ๋กœ๋ฅผ ์ ์–ด์ค€๋‹ค. ๋‚˜๋Š” ์ ˆ๋Œ€๊ฒฝ๋กœ๋กœ ๋„ฃ์–ด์ฃผ์—ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  โ€“rm ๋’ค์—๋Š” ์‚ฌ์šฉํ•  ๋„์ปค์ด๋ฏธ์ง€ ํ’€๋„ค์ž„์„ ์“ฐ๊ณ  ์‹คํ–‰..!

docker run --gpus all -it -v $(pwd):/home/clkim/GONGIN --rm  nvidia/cuda:10.0-cudnn7-devel-ubuntu18.04

image

run ์ดํ›„ ์ถ”๊ฐ€๋กœ ์„ค์น˜ํ•ด ์ค€ ๊ฒƒ!

apt-get update -y
apt-get -y install libgl1-mesa-glx
apt-get install -y python3-pip python-dev build-essential
pip3 install --upgrade pip
apt-get install vim
pip install tensorflow-gpu==2.0.0

๋งŒ์•ฝ ์ฒซ์ค„๋ถ€ํ„ฐ ๋‹ค์Œ๊ณผ ๊ฐ™์€ GPG KEY ์—๋Ÿฌ๊ฐ€ ๋‚œ๋‹ค๋ฉด..

image

์•„๋ž˜ ๋ช…๋ น์–ด ์‹คํ–‰ํ•˜๋ฉด ๋œ๋‹จ๋‹ค!

apt-key del 7fa2af80 && apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/3bf863cc.pub

ํ•˜์ง€๋งŒ ๋‚œ ์•ˆ๋˜๋ฏ€๋กœ.. ์•„๋ž˜ ์‚ฌ์ดํŠธ๋“ค์„ ์ฐธ๊ณ ํ•˜์—ฌ์„œ pub key ์ง€์šฐ๊ณ  ๋ณธ์ธ์ด ํ•ด๋‹นํ•˜๋Š” cuda ๋ฒ„์ „์˜ key๋ฅผ ๋ฐ›์•„์„œ ์จ์ฃผ์ž https://developer.nvidia.com/blog/updating-the-cuda-linux-gpg-repository-key/

https://forums.developer.nvidia.com/t/updating-the-cuda-linux-gpg-repository-key/212897/7

์˜ˆ์‹œ))

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-keyring_1.0-1_all.deb

๋˜ํ•œ, TIME OUT ์—๋Ÿฌ์‹œ ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ด๋ณด์ž

sudo pip install --default-timeout=100 future

์—๋Ÿฌ๋“ค์„ ํ•ด๊ฒฐํ–ˆ๋‹ค๋ฉด ๋‹ค์Œ basrh ์— cuda ์ •๋ณด๋ฅผ ์ถ”๊ฐ€ํ•˜์ž!

vim ~/.bashrc

ํ•˜๋ฉด bashrc ์ฝ”๋“œ๊ฐ€ ๋‚˜์˜ค๋Š”๋ฐ, ์—ฌ๊ธฐ์—๋‹ค๊ฐ€ ๋ณธ์ธ์˜ cuda ๋ฒ„์ „์— ๋งž๊ฒŒ๋” ์ˆ˜์ •ํ•˜์—ฌ์„œ ๋งจ ์•„๋ž˜์—๋‹ค๊ฐ€ ์•„๋ž˜ ๋‚ด์šฉ์„ ์‚ฝ์ž…ํ•ด์ฃผ์ž! ๋‚˜๋Š” cuda 10.0 ์ด๋ผ์„œ 10.0

# <<< conda initialize <<<
export PATH=$PATH:/usr/local/cuda-10.0/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.0/lib64
export CUDADIR=/usr/local/cuda-10.0
export CUDA_NVRTC_LIB=/usr/local/cuda-10.0/include/nvrtc.h
export CUDA_HOME=/usr/local/cuda-10.0/
source ~/.bashrc

์ด๋Ÿฐ์‹์œผ๋กœ ๋ณธ์ธ์ด ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋“ฑ์„ ์„ค์น˜ํ•˜์—ฌ ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑํ•˜์˜€๊ณ , ํŒŒ์ผ์ด ์ž˜ ๋Œ์•„๊ฐ„๋‹ค๋ฉด ์™„์„ฑ! ์ด๋‹ค.

image push

์ด์ œ ์ตœ์ข…์ ์œผ๋กœ ๋‚ด๊ฐ€ ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์ด ๋‹ค ์„ค์น˜๋œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ image ๋กœ ๋งŒ๋“ค์–ด push ํ•˜๋ฉด๋œ๋‹ค.

๋จผ์ €, ํ˜„ container ์ƒํƒœ๋กœ image ๋กœ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ด์ค€๋‹ค.

docker commit -m [image ์„ค๋ช…] -a [ ์‚ฌ์šฉ์ž mail ] [ container Name or ID ] [ ์ƒ์„ฑํ•  image name : Tag ]

docker commit -m "tensorflow 2.0 image with cuda10.0" -a "example@naver.com" bbEXAMPLE75fb5 example:v0.1

์•”ํ˜ธ๋ฌธ์ž๊ฐ™์€๊ฒƒ์ด ์ƒ์„ฑ๋˜์—ˆ๋‹ค image

์ด๋ฏธ์ง€ ์ƒ์„ฑํ™•์ธ! ์„ฑ๊ณตํ•˜์˜€๋‹ค. image

์ด์ œ image tag ์ž‘์—…์„ ํ•ด์ฃผ์ž! ๋‚ด ์•„์ด๋””๋ฅผ ์•ž์— ์จ์ฃผ๋ฉด ๋œ๋‹ค.

docker tag [ image name or Tag ] [ docker hub ID ํ˜น์€ private registry ip:port ]

docker tag noah:v1.0 zzennin/noah:v1.0

์ด์ œ push ํ•ด์ฃผ์ž (push ๋Š” docker login ํ•œ ์ƒํƒœ์—์„œ ํ•˜๋Š”๊ฑฐ ์žŠ์ง€ ๋ง์ž)

docker push noah:v1.0

์ด์ œ ๋!

/ . . . ํ•˜๋ฉด ์ข‹์„ํ…๋ฐ ๋‚˜๋Š” ๋˜ ์—๋Ÿฌ.. ์—๋Ÿฌ๋‚œ ์‚ฌ๋žŒ ์—ฌ๊ธฐ ๋ชจ์—ฌ~

image

์•„๋ž˜ ์‚ฌ์ดํŠธ๋Œ€๋กœ nameserver ์ถ”๊ฐ€ํ•ด์ค€ ํ›„ restart ํ•ด์ฃผ๋‹ˆ ๋˜์—ˆ๋‹ค! ๊ตฟ!

https://stackoverflow.com/questions/47580528/error-response-from-daemon-get-https-registry-1-docker-io-v2-dial-tcp-look

์•Œ์•„๋‘๋ฉด ํŽธ๋ฆฌํ•œ ๋„์ปค ๋ช…๋ น์–ด๋“ค!

๋„์ปค ์ปจํ…Œ์ด๋„ˆ ๋น ์ ธ๋‚˜์˜ค๊ธฐ

๊ทธ๋ƒฅ exit ์น˜๊ณ  ์—”ํ„ฐ~

๊ฐ™์€ image์˜ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ๋” ๋งŒ๋“ค๊ธฐ

์ปจํ…Œ์ด๋„ˆ ๋” ์—ด๊ณ ์‹ถ์œผ๋ฉด! container id ๋ฅผ ์•Œ๊ณ  ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์น˜๋ฉด ๋จ

docker exec -it [container id ํ˜น์€ ์ด๋ฆ„] /bin/bash

docker exec -it 2fee1f881c52 /bin/bash

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ