CUDA Docker 컨테이너 만들기

인공능지연구소·2024년 6월 6일

Dockerfile

# Base image
FROM nvidia/cuda:12.1.0-devel-ubuntu20.04

# Set environment variables for terminal
ENV TERM xterm-256color
ENV DEBIAN_FRONTEND=noninteractive

# Install sudo and other necessary packages
RUN apt-get update && apt-get install -y sudo \
    && apt-get install -y tzdata \
    && ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime \
    && dpkg-reconfigure --frontend noninteractive tzdata \
    && apt-get install -y xorg openbox

# Create a new user 'user'
RUN useradd -ms /bin/bash user \
    && echo "user:user" | chpasswd \
    && adduser user sudo

# Set the working directory to user's home
WORKDIR /home/user

# Ensure the user can use sudo without a password prompt
RUN echo 'user ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

# Change to non-root user
USER user

# Set the default shell
SHELL ["/bin/bash", "-c"]

# Entrypoint
ENTRYPOINT ["/bin/bash"]

build.sh

#!/bin/bash

# Build the Docker image
docker build -t nvidia/cuda:12.1.0-devel-ubuntu20.04-custom .

run.sh

#!/bin/bash
xhost +local:root

# Run the Docker container with the necessary options
docker run --gpus all -it \
    --name basic_cuda_container \
    -e DISPLAY=$DISPLAY \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -v /home/user/Docker:/home/$(whoami)/Docker \
    -v /etc/localtime:/etc/localtime:ro \
    nvidia/cuda:12.1.0-devel-ubuntu20.04-custom
profile
내가 뭘 해봤는지는 시리즈 탭에 다 정리해뒀슈

0개의 댓글