본문 바로가기

dev

GPU 서버 개발 환경 구축

0. 들어가며

  • GPU 서버에서 Docker 기반의 개발 환경을 구축하는 방법

1. Docker container 생성

1.1. 서버 접속

  • 환경 구축을 진행할 서버에 접속한 뒤 원하는 경로로 이동한다.
ssh -p {PORT} {USER}@{IP}
cd {DIRECTORY}

1.2. Dockerfile 작성

  • Dockerfile을 작성한다.
  • runtime vs devel: runtime은 가볍지만 nvcc가 설치되어있지 않다. 따라서 devel을 사용해야 한다.
  • sending build context to Docker daemon에서 너무 많은 용량을 사용할 경우, 빈 폴더에 Dockerfile을 넣은 뒤 build한다.
vim Dockerfile

 

# base image
FROM pytorch/pytorch:2.0.0-cuda11.7-cudnn8-devel

# install packages
RUN apt-get update -y && \
    apt-get install -y openssh-server vim git wget unzip sshfs screen && \
    apt-get install -y libopenmpi-dev libgl1-mesa-glx

# install python libraries
RUN pip install jupyterlab pytorch_lightning transformers datasets hydra-core wandb --no-cache-dir 

# cleaning
RUN apt-get autoremove -y && \
    apt-get clean && \
    rm -rf /root/.cache

# edit ssh config
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

VOLUME /mnt
VOLUME /workspace
WORKDIR /workspace
EXPOSE 22 80 8000 8512 8888

RUN alias python=python3
RUN alias pip=/opt/conda/bin/pip
RUN alias conda=/opt/conda/bin/conda

CMD ["/bin/bash"]

1.3. Container 생성

  • shm-size=8G: 공유 메모리 크기 키우기
  • windows의 경우에는 $PWD 대신 ${PWD} 사용
docker build -t my-image .
docker run -dit --gpus all --name my-container --privileged --shm-size=8G -p 22:22 -p 80:80 -p 8000:8000 -p 8512:8512 -p 8888:8888 -v $PWD:/workspace my-image bash

1.4. Container 접속

docker exec -it my-container bash

 

2. 주요 설정

2.1. SSH

  • 접속에 사용할 root계정의 비밀번호를 만든다.
passwd root
  • ssh service 시작
service ssh start

2.2. Jupyter 실행

  • jupyter 비밀번호 설정
jupyter lab --generate-config
jupyter lab password
  • jupyter 실행 (background)
nohup jupyter lab --allow-root --ip 0.0.0.0 &

'dev' 카테고리의 다른 글

Sentinel Hub API로 위성 사진 수집하기  (0) 2023.07.18
GNU screen 사용법  (0) 2023.05.18
neo4j docker로 배포하기  (0) 2023.05.17
Neo4j Python library 사용법  (0) 2023.05.09