ubuntu-drivers devices
# nvidia-driver-515 설치
sudo apt -y install nvidia-driver-515
# (참고) 자동으로 드라이버 버전 선택하여 설치
# sudo ubuntu-drivers autoinstall
# 다음 명령어로 드라이버가 정상적으로 작동되는지 확인합니다. (GPU 장치 및 활용 상태 확인)
nvidia-smi
본 설치는 docker docs를 따라갑니다.
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo usermod -a -G docker $USER
sudo service docker restart
docker --help
본 설치는 nvivia-docker guide를 따라갑니다.
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
&& curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/experimental/$distribution/libnvidia-container.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt-get update
sudo apt-get install -y nvidia-docker2
# 데몬 재시작
sudo systemctl restart docker
# (option) 설치 확인
sudo docker run --rm --gpus all nvidia/cuda:11.0.3-base-ubuntu20.04 nvidia-smi
본 Dockerfile은 nvidia/cuda를 기반으로 제작되었습니다.
도커 파일의 전반적인 맥락은 다음과 같습니다.
FROM nvidia/cuda:11.7.1-cudnn8-devel-ubuntu22.04
# Remove any third-party apt sources to avoid issues with expiring keys.
RUN rm -f /etc/apt/sources.list.d/*.list
# Install some basic utilities & python prerequisites
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y && apt-get install -y --no-install-recommends\
vim \
curl \
apt-utils \
ssh \
tree \
ca-certificates \
sudo \
git \
bzip2 \
libx11-6 \
make \
build-essential \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
wget \
llvm \
libncursesw5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
libffi-dev \
liblzma-dev \
python3-openssl && \
rm -rf /var/lib/apt/lists/*
# Set up time zone
ENV TZ=Asia/Seoul
RUN sudo ln -snf /usr/share/zoneinfo/$TZ /etc/localtime
# Add config for ssh connection
RUN echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config && \
echo "PermitEmptyPasswords yes" >> /etc/ssh/sshd_config
# Create a non-root user and switch to it & Adding User to the sudoers File
ARG USER_NAME user
ARG USER_PASSWORD 0000
RUN adduser --disabled-password --gecos '' --shell /bin/bash $USER_NAME && \
echo "$USER_NAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USER_NAME && \
echo "$USER_NAME:$USER_PASSWORD" | chpasswd
USER $USER_NAME
# All users can use /home/user as their home directory
ENV HOME /home/$USER_NAME
RUN mkdir $HOME/.cache $HOME/.config && \
chmod -R 777 $HOME
# Re-run ssh when the container restarts.
RUN echo "sudo service ssh start > /dev/null" >> $HOME/.bashrc
# Create a workspace directory
RUN mkdir $HOME/workspace
WORKDIR $HOME/workspace
# Set up python environment with pyenv
ARG PYTHON_VERSION 3.10.6
RUN curl https://pyenv.run | bash
ENV PYENV_ROOT="$HOME/.pyenv"
ENV PATH "$PYENV_ROOT/bin:$PYENV_ROOT/shims:$PATH"
ENV eval "$(pyenv init -)"
RUN cd $HOME && /bin/bash -c "source .bashrc" && \
/bin/bash -c "pyenv install -v $PYTHON_VERSION" && \
/bin/bash -c "pyenv global $PYTHON_VERSION"
# Install Poetry
ENV PATH "$HOME/.local/bin:$PATH"
ENV PYTHON_KEYRING_BACKEND keyring.backends.null.Keyring
RUN curl -sSL https://install.python-poetry.org | python - && \
poetry config virtualenvs.in-project true && \
poetry config virtualenvs.path "./.venv"
# [option] Set up DL development environment (with poetry)
RUN mkdir $HOME/workspace/machine-learning
WORKDIR $HOME/workspace/machine-learning
COPY pyproject.toml $HOME/workspace/machine-learning/pyproject.toml
RUN /bin/bash -c "pyenv local $PYTHON_VERSION" && \
poetry env use python3 && \
poetry run poetry install --no-cache
CMD cd $HOME/workspace/machine-learning && \
poetry run jupyter lab --ip 0.0.0.0 --allow-root \
--NotebookApp.token= --no-browser --notebook-dir=$HOME
docker build -t dl-world:cuda11.7.1-cudnn8-ubuntu22.04 \
--build-arg USER_NAME=<username> \
--build-arg USER_PASSWORD=<password> \
--build-arg PYTHON_VERSION=<python-version> .
docker run -itd --name test-container \
--gpus all -p 2222:22 \
--restart always \
-v <volume-name>:<container-folder> \
-w <workspace> \
dl-world:cuda11.7.1-cudnn8-ubuntu22.04
dldev의 기본 CMD는 jupyter lab 서버를 실행시킵니다(비밀번호 x).
보안을 위해 비밀번호를 설정하고 싶으시면 여기를 참고해주세요.
Docker Hub를 이용하기 위해선, 먼저 회원가입이 필요합니다.
docker login
docker tag <image-name>:<tag> <username>/<new-image-name>:<new-tag>
docker push <username>/<imagename>:<tag>