docker
https://blog.roboflow.com/nvidia-docker-vscode-pytorch/
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nvcr.io/nvidia/pytorch 24.08-py3 c4c51e501ca9 3 weeks ago 20.4GB
$ mkdir -p /raid/templates/sixxdisk/
$ cd ~
$ ln -s /raid/templates/sixxdisk/
$ docker run -it -d --name sixxos -v ~/sixxdisk:/workspace nvcr.io/nvidia/pytorch:24.08-py3 /bin/bash
2e3..................
$ docker run --gpus all --name sixxos -v ~/sixxdisk:/workspace -it -d --rm nvcr.io/nvidia/pytorch:24.08-py3 /bin/bash
# rm์ docker stopํ๋ฉด ์์์ rm๋จ.
$ docker run --gpus all --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 --name sixxos -v ~/sixxdisk:/workspace -it -d nvcr.io/nvidia/pytorch:24.08-py3
$ docker exec -it sixxos /bin/bash$ docker run --gpus all --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 --name sixxos -v ~/sixxdisk:/workspace -it -d nvcr.io/nvidia/pytorch:24.08-py3
docker run: Docker ์ปจํ
์ด๋๋ฅผ ์คํํ๋ ๊ธฐ๋ณธ ๋ช
๋ น์ด
--gpus all: ์ปจํ
์ด๋๊ฐ ํธ์คํธ ์์คํ
์ ๋ชจ๋ GPU๋ฅผ ์ฌ์ฉํ ์ ์๋๋ก ์ค์ ํฉ๋๋ค.
--ipc=host: ์ปจํ
์ด๋๊ฐ ํธ์คํธ์ IPC ๋ค์์คํ์ด์ค๋ฅผ ์ฌ์ฉํ๋๋ก ์ค์ .
์ด๋ ํ๋ก์ธ์ค ๊ฐ ํต์ ์ ์ํด ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๊ณต์ ํ ๋ ์ ์ฉ
--ulimit memlock=-1: ์ปจํ
์ด๋ ๋ด์์ ๋ฉ๋ชจ๋ฆฌ ์ ๊ธ ์ ํ์ ํด์ .
์ด๋ ์ ํ๋ฆฌ์ผ์ด์
์ด ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ ๊ธ ์ ์๋๋ก ํ์ฉํฉ๋๋ค.
--ulimit stack=67108864: ์ปจํ
์ด๋ ๋ด์์ ์คํ ํฌ๊ธฐ ์ ํ์ ์ค์ ํฉ๋๋ค.
์ฌ๊ธฐ์๋ ์คํ ํฌ๊ธฐ๋ฅผ 64MB๋ก ์ค์ ํฉ๋๋ค.
--name sixxos: ์ปจํ
์ด๋์ ์ด๋ฆ์ sixxos๋ก ์ค์
-v ~/sixxdisk:/workspace: ํธ์คํธ ์์คํ
์ ~/sixxdisk ๋๋ ํ ๋ฆฌ๋ฅผ ์ปจํ
์ด๋ ๋ด์ /workspace ๋๋ ํ ๋ฆฌ์ ๋ง์ดํธํฉ๋๋ค. ์ด๋ ํธ์คํธ์ ์ปจํ
์ด๋ ๊ฐ์ ํ์ผ์ ๊ณต์ ํ ์ ์๋๋ก ํฉ๋๋ค.
-it: -i์ -t ์ต์
์ ๊ฒฐํฉํ ๊ฒ์ผ๋ก, ์ปจํ
์ด๋์ ํ์ค ์
๋ ฅ์ ์ด์ด๋๊ณ TTY๋ฅผ ํ์ฑํํฉ๋๋ค.
์ด๋ ํฐ๋ฏธ๋์์ ์ํธ์์ฉํ ์ ์๋๋ก ํฉ๋๋ค.
-d: ์ปจํ
์ด๋๋ฅผ ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์คํํฉ๋๋ค.
์ด๋ ์ปจํ
์ด๋๊ฐ ํฐ๋ฏธ๋์ ์ ์ ํ์ง ์๊ณ ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์คํ๋๋๋ก ํฉ๋๋ค.
nvcr.io/nvidia/pytorch:24.08-py3: ์ฌ์ฉํ Docker ์ด๋ฏธ์ง๋ฅผ ์ง์
Process
Linux์ ๊ธฐ๋ณธ๊ธฐ๋ฅ์ ํ์ฉํ์ฌ “Process”(Directory/ File)๋ฅผ ๊ฐ์์ผ๋ก ๋ถ๋ฆฌ ,
์์์(CPU,MEMORY,I/O) ๋ถ๋ฐฐํ์ฌ ์๋ฒ๊ด๋ฆฌ
Container
What even is a containerโ by Julia Evans.
๊ฐ๋ฐ์๊ฐ-์ฒ์-docker-์ ํ ๋-์ค๋-๋ฉ๋ถ-๋ช๊ฐ์ง
Container๋ (Virtual machine๊ณผ ๊ฐ์ด ํ๋์ ์จ์ ํ ์๋ฒ๋ฅผ ์ ๊ณตํ๋ ๊ฒ์ด ์๋๋ผ)
๋ช
๋ น์ ์คํํ๋ ํ๊ฒฝ๋ง ์ ๊ณตํ๊ณ ๊ทธ ๋ช
๋ น์ ์คํํ์ฌ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ฌ ์ค ๋ฟ์ด๋ค.
๋ ํ๋์ ๋ ๋ฆฝ๋ Process
- Namespaces
- Chroot (Changing the room – root directory)
- Cgroups (Control groups)
$ docker images
ubuntu latest edbfe74c41f8 5 weeks ago 78.1MB
$ docker run --name u_test ubuntu
# ์ด๋ฏธ์ง๋ง ๋ค์ด๋ฐ๊ณ , ์ ์ process๊ฐ ์คํ๋์๋ค๊ฐ ์ฃฝ๋๋ค. (์์ ์๋ณด์)
$ docker ps
# ์๋ณด์ . ์ฃฝ์ด์..
$ docker ps -a | grep u_test
#CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
#59efb951e058 ubuntu "bash" 37 seconds ago Exited (0) 36 seconds ago u_test
$ docker rm ubuntu_test$ docker run --name ubuntu_test ubuntu "ls"
#bin
#boot
#dev
...
# ์ด๋ฏธ์ง๋ง ๋ค์ด๋ฐ๊ณ , ์ ์ process๊ฐ ์คํ๋์ด ls๋ง ๋ ๋ฆฌ๊ณ ์ฃฝ๋๋ค.
$ docker rm u_test### -it interactive tty
$ docker run --name u_test -it ubuntu
# ์ฌ๊ธฐ์ ubuntu ์๋ฒ๊ฐ ์คํ๋์๋ค๋ ์ฐฉ๊ฐํ ์ ์์ง๋ง, shell์์ exit๋ก ๋์ค๋ ์๊ฐ ์ปจํ
์ด๋๋ ์ค์ง๋๋ค.
### -d detached mode
$ docker run --name u_test -d ubuntu
# background๋ก ๋ ์์๊ฒ ๊ฐ์ง๋ง, ๋ฐ๋ก Exit ์ค์ง๋๋ค.
# "์ปจํ
์ด๋ ์คํ"์ HostOS์์ ํ๋ก์ธ์ค๋ฅผ ์คํํ๋ ๊ฒ๊ณผ ๊ฐ์ ๊ฐ๋
์ด๊ธฐ ๋๋ฌธ์
# ์ปจํ
์ด๋์์ ์คํ๋๋ ๋ช
๋ น์ด ๊ณ์ ์คํ๋ ์ํฉ์ด ์๋๋ฉด, ๊ทธ ๋ช
๋ น์ด ์ข
๋ฃ๋๊ณ , ๋์์ ์ปจํ
์ด๋๋ ์ข
๋ฃ๋๋ค.
$ docker run --name u_test -d -it ubuntu
# ์คํ ์ค์ธ Docker ์ปจํ
์ด๋์ ๊ธฐ๋ณธ ํ๋ก์ธ์ค์ ํฐ๋ฏธ๋์ ์ฐ๊ฒฐ
$ docker attach u_test
# shell์ ๋ฐฑ๊ทธ๋ผ์ด๋๋ก ์คํํ๋๋ฐ๋ ์ฑ๊ณตํ์ง๋ง, shell์์ exit๋ก ๋์ค๋ ์๊ฐ ์ปจํ
์ด๋๋ ์ค์ง๋๋ค.
$ docker run --name ubuntu_test -d -it --rm ubuntu /bin/bash -c \\
'while true; do echo "still live"; sleep 6; done'
$ docker attach ubuntu_test
#still live
#still live
# ...
$ docker run --name ubuntu_test -d -it --rm ubuntu
$ docker exec -it 8e0 /bin/bash
# ๋์ปค ์ปจํ
์ด๋์์ ์คํ๋๋ ์ ํ๋ฆฌ์ผ์ด์
์๋ฒ์ (background๋ชจ๋๊ฐ ์๋) foreground๋ชจ๋๋ก ์คํํด์ผ ํ๋ค.
# foreground๋ก ์คํ๋์ด ์๊ธฐ ๋๋ฌธ์, ํด๋น์๋ฒ๊ฐ ์ฌ์์๋๋ฉด ํด๋น ์ปจํ
์ด๋๊ฐ ์ข
๋ฃ๋๋ค.
# docker Attach๋ ์ปจํ
์ด๋์ ๊ธฐ๋ณธ ํ๋ก์ธ์ค์ ์ฐ๊ฒฐํ๋ ๋ฐ๋ฉด docker exec๋ ๊ธฐ๋ณธ ํ๋ก์ธ์ค์ ์ํฅ์ ์ฃผ์ง ์๊ณ ์ปจํ
์ด๋ ๋ด๋ถ์ ์ ํ๋ก์ธ์ค(์: ์ ์
ธ)๋ฅผ ์์ฑ์ปจํ ์ด๋ ์ํ
docker run ๋ช ๋ น์ด๋ ์ค์ ๋ก ๋ค์์ ์ธ ๋ช ๋ น์ด๋ฅผ ํ ๋ฒ์ ์คํํ๋ ๊ฒ๊ณผ ๊ฐ๋ค.
- docker pull : ์ด๋ฏธ์ง๋ฅผ ๋ค์ด๋ก๋ํ๋ค. docker run ๋ช ๋ น์ด๋ ์ด๋ฏธ์ง๊ฐ ๋ก์ปฌ์ ์์ผ๋ฉด ์ด๋ฏธ์ง๋ฅผ ๋ค์ด๋ก๋ํ๋ค.
- docker create : ์ด๋ฏธ์ง๋ก๋ถํฐ ์ปจํ ์ด๋๋ฅผ ์์ฑํ๋ค.
- docker start : ์ปจํ ์ด๋๋ฅผ ์์ํ๋ค.
docker run ๋ช ๋ น (= “create” + “start” ๋ช ๋ น์ ํ๋ฒ์ ์คํ)

์ปจํ ์ด๋์ ์ด๋ฏธ์ง์ ์ฐจ์ด
์ด๋ฏธ์ง๋ ์ถ์์ ์ธ ๊ฐ๋
์ด๊ณ , ์คํ์ ์ด๋ฏธ์ง๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์์ฑ๋ ์ปจํ
์ด๋์์
๋์ปค ์ด๋ฏธ์ง๋ฅผ pull๋ก ๋ฐ์์ค๊ณ commit ์ผ๋ก ํ์๋ ์ด๋ฏธ์ง๋ฅผ ๋ง๋ค๊ณ , ์ญ์ ๋ rmi ๋ช
๋ น์ด๋ก




๋ช ๋ น
๋ช ๋ น์ (์๋ฒ์์ ์คํํ๋ ๊ฒ์ด ์๋) Client์์ ์คํ

docker run ๋ช ๋ น์ ์ต์
-it interactive terminal
-d ๋ฐฑ๋ผ์ด๋๋ก ํ๋ก์ธ์ค๋ฅผ ์ด์ํ ๋ detached ๋ชจ๋๋ผ ํ๋ค.
-e ํ๊ฒฝ๋ณ์
-p Host์ Container์ ํฌํธ ์ฐ๊ฒฐ
-v Host์ Container์ ํด๋ ์ฐ๊ฒฐ
–rm
–name
์ด๋ฏธ์ง ์กด์ฌ์ฌ๋ถํ์ธ ํ, ํ๋ก์ธ์ค ์คํ, ๋ช ๋ น์ด์ ๋ฌ
docker exec ๋ช ๋ น
์ปจ๋ฐ์ด๋์ ssh์๋ฒ์ ์ ์ํ๋ ๊ฒ์ฒ๋ผ ์ง์ ์ ์

docker Images

docker network
docker network create mynet
docker network connect mynet mysql
docker rm
$ docker volume ls | awk '{print $2}' |xargs docker volume rm
docker compose
๋ช ๋ น ๋ฐ ์ต์ ์ docker-compose.yml์ dictionaryํํ๋ก
ENTRYPOINT vs. CMD
์ปจํ ์ด๋ ์์์ ์คํ ๋ช ๋ น์ ๋ํ Default ์ง์ ์ฌ๋ถ
Image ๋ง๋ค๊ธฐ
- docker commit
- docker build -t onesixx/ubuntu:myfile .
๋ง๋ค์ด๋์ Dokerfile๋ฅผ ์ฐธ์กฐํ์ฌ –tag list ์ ์ด๋ฆ์ผ๋ก ์ด๋ฏธ์ง๋ฅผ ์์ฑ
Image
<Namespace>/<Image_name>:<Tag>
์ฌ๋ฌ Layer๋ก ๊ตฌ์ฑ๋จ (Union Mount ๊ณ์ธตํ๋ ํ์ผ์์คํ
)
Tip
sudo ์์ด ์ฌ์ฉํ๊ธฐ
$ sudo usermod -aG docker onesixx # onesixx (๋์ $USER๋ฅผ ์ฌ์ฉํ๋ฉด ์ ์ํ) ์ฌ์ฉ์์๊ฒ ๊ถํ๋ถ์ฌ
์๋น์ค ํ์ธ
> sudo service --status-all [ - ] cron [ - ] dbus [ ? ] hwclock.sh [ - ] procps [ ? ] rstudio-server [ ? ] shiny-server [ + ] ssh [ - ] supervisor [ + ] udev [ - ] unattended-upgrades [ - ] x11-common > sudo service rstudio-server restart
๊ธฐ๋ณธ์์ (using git)
Clone using git
์ํ๋ image๋ฅผ clone(download)ํ๋ค. ๋๋ dockerfile ์ฌ์ฉ
~|โ$ git clone https://github.com/docker/doodle.git Cloning into 'doodle'... remote: Enumerating objects: 73, done. remote: Total 73 (delta 0), reused 0 (delta 0), pack-reused 73 Receiving objects: 100% (73/73), 21.61 KiB | 1.54 MiB/s, done. Resolving deltas: 100% (28/28), done.
Build an image
ํด๋น image(private file system)๋ฅผ ๊ธฐ๋ฐ์ผ๋ก Container๋ฅผ buildํ๋ค.
(-t ๋ –tag )
~|โ$ cd doodle/cheers2019 && docker build -t onesixx/cheers2019 . Sending build context to Docker daemon 12.8kB Step 1/9 : FROM golang:1.11-alpine AS builder Step 2/9 : RUN apk add --no-cache git Step 3/9 : RUN go get github.com/pdevine/go-asciisprite Step 4/9 : WORKDIR /project Step 5/9 : COPY cheers.go . Step 6/9 : RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o cheers cheers.go Step 7/9 : FROM scratch Step 8/9 : COPY --from=builder /project/cheers /cheers Step 9/9 : ENTRYPOINT ["/cheers"] Successfully built 42ac2c9c8f7b Successfully tagged onesixx/cheers2019:latest
Run
Container๋ฅผ Runํ๋ค. ์ฆ application์ launchํ๋ค.
์ต์
: -i (interactive) -t (tty)
์ปค๋งจ๋: –rm (remove containers)
~/doodle/cheers2019|โ$ docker run -it --rm onesixx/cheers2019
Share Repository
docker tag cheers2019 onesixx/cheers2019 (์๋ต)๋ก ๊ธฐ์กด image๋ฅผ ์ฐธ์กฐํ ์๋ก์ด image๋ฅผ ๋ง๋ ๋ค.
Docker hub์ pushํ์ฌ shareํ๋ค.
~/doodle/cheers2019|โ$ docker login && docker push onesixx/cheers2019 Authenticating with existing credentials... Login Succeeded The push refers to repository [docker.io/onesixx/cheers2019] c53df6ff62fc: Pushed latest: digest: sha256:bb6f53d68650d1b443bf9364a07291ac5686ac72970af69f32ff8e226b760d1e size: 528
๊ธฐ๋ณธ์์ (using dockerfile)
dockerfile
์ํ๋ image๋ฅผ clone(download)ํ๋ค. ๋๋ dockerfile ์ฌ์ฉ
FROM trestletech/plumber MAINTAINER Docker User [email protected] RUN echo "alias ll='ls -alF'" >> ~/.bashrc RUN /bin/bash -c 'source $HOME/.bashrc;' RUN echo "https_proxy=http://10.250.59.224:3128" >> /usr/lib/R/etc/Renviron.site RUN echo "http_proxy=http://10.250.59.224:3128" >> /usr/lib/R/etc/Renviron.site RUN R -e "install.packages('pacman', lib=.Library)" CMD ["/home/oschung_skcc/RCODE/plumb/model-api/plumber.R"]
$ docker images
Build an image (from a Dockerfile)
ํด๋น image(private file system)๋ฅผ ๊ธฐ๋ฐ์ผ๋ก Container๋ฅผ buildํ๋ค.
(-t ๋ –tag )
~|โ$ docker build -t onesixx/plumb1 . Sending build context to Docker daemon 12.8kB Step 1/9 : FROM golang:1.11-alpine AS builder Step 2/9 : RUN apk add --no-cache git Step 3/9 : RUN go get github.com/pdevine/go-asciisprite Step 4/9 : WORKDIR /project Step 5/9 : COPY cheers.go . Step 6/9 : RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o cheers cheers.go Step 7/9 : FROM scratch Step 8/9 : COPY --from=builder /project/cheers /cheers Step 9/9 : ENTRYPOINT ["/cheers"] Successfully built 42ac2c9c8f7b Successfully tagged onesixx/cheers2019:latest
Run
Container๋ฅผ Runํ๋ค. ์ฆ application์ launchํ๋ค.
์ต์
: -i (interactive) -t (tty)
์ปค๋งจ๋: –rm (remove containers)
โ$ docker run -it -d -p 8000:8000 -v vol-rstudio-home:/home onesixx/plumb1 \\ /home/oschung_skcc/RCODE/plumb/model-api/plumber.R
docker exec -it 3da /bin/bash