For the beginner
docker architecture
docker run을 통해 컨테이너를 실행
$ docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Options:
-d, --detach Run container in background and print container ID
-e, --env list Set environment variables
-i, --interactive Keep STDIN open even if not attached
-p, --publish list Publish a container's port(s) to the host
--rm Automatically remove the container when it exits
-t, --tty Allocate a pseudo-TTY
-v, --volume list Bind mount a volume
-w, --workdir string Working directory inside the container
$ docker run -it \
{{base image}} \
python train.py
$ docker run -dt \
zironycho/pytorch:1.1.0-slim \
python train.py
$ docker run -it \
-v $(pwd):/workspace \
-w /workspace \
zironycho/pytorch:1.1.0-slim \
python train.py
$ docker run -it \
--rm \
zironycho/pytorch:1.1.0-slim \
python train.py
$ docker run -it \
-p 9999:8888 \
zironycho/pytorch-jupyter:1.1.0-slim \
jupyter notebook --ip 0.0.0.0 --port 8888 --no-browser --allow-root
- ip에 주의
$ docker run -it \
-e MAX_EPOCH=100 \
-v $(pwd)/tacotron:/workspace \
-v /database:/database/data \
-w /workspace \
zironycho/pytorch:1.1.0-slim \
python train.py
- volume으로 mount하지 않는 이상 날아감
registry for nvidia optimized image
- nvcr.io/nvidia/pytorch:19.05-py3
- ...
그 밖의 자주 사용하는 commands
$ docker exec -it {{container_id}} bash
$ docker logs -f {{container_id}}
$ docker ps
$ docker ps -a
$ docker stop {{container_id}}
- or
rm
$ docker images
docker image를 만들기 위한 description
FROM zironycho/pytorch:1.1.0-slim
WORKDIR /workspace
COPY requirements.txt .
RUN pip install -r requirements.txt && rm -rf /root/.cache/pip
RUN apt get update
- cache: file status
$ docker build -t my-pytorch:v1 -f docker/Dockerfile .
-
ignore file/dir when it build
.dockerignore
를 이용하여 image를 생성할 때 layer에 포함시키지 않기
**/__pycache__
**/.idea
**/generated
.pytest_cache
**/*.pyc
**/*.wav
**/*.png
**/*.t7
-
필요한 파일만 copy하기.
- union file system
- example) copy again, again, again
config file for multi-container applications
version: "3.7"
services:
train-1:
build:
context: .
dockerfile: ./docker/Dockerfile
command: python train.py
volumes:
- .:/workspace
- my-database:/database
environment:
- MAX_EPOCH=100
- NVIDIA_VISIBLE_DEVICES=0
train-2:
image: zironycho/pytorch-jupyter:1.1.0-slim
environment:
- HELLO=WORLD
- NVIDIA_VISIBLE_DEVICES=1,2
ports:
- "8888:8888"
volumes:
my-database:
driver: local
nvidia gpu를 사용하기 위해서는 nvidia-docker를 사용함.
$ docker run --runtime=nvidia \
--rm \
nvidia/cuda:9.0-base nvidia-smi