최근 O-RAN 시뮬레이션 환경을 설정하면서 굉장히 복잡한 초기 세팅을 한 적이 있다. 다른 팀원에게 동일한 환경을 설정하기 위해 docker를 사용해 보기로 결심했다.
그동안 GPU를 활용하는 딥러닝 환경 구축에 많은 시간을 써왔다. 근데 docker hub에서 환경 구축이 완료된 상태의 이미지를 다운받고 그것을 컨테이너 형태로 실행하면 되더라는 신세계를 맛보게 되었다..
이제 이 친구를 활용해서 nvidia 드라이버 설치부터 cuda 라이브러리 설치 등등 멀고도 험난한 머신러닝 환경 세팅을 한큐에 끝내보도록 하자.
pull
한 다음 run
하면 되겠지?host OS 쪽에서의 그래픽 드라이버 설치는 진행했다고 가정한다(필자는 GTX 1650, ubuntu 24.04에서 nvidia-driver-535-server 드라이버 설치). ubuntu에서의 드라이버 설치는 이 공식 문서를 참고해보자...
본문에 보면 host OS 쪽에서 nvidia container toolkit을 설치해야 한다고 한다.
(nvidia-docker2
는 cuda 10 버전을 깔지 않는 이상 필요하지 않다고 한다.)
데비안 계열 환경에서는 레포지토리 등록을 거쳐 APT로 한방에 설치할 수 있다. 공식 문서를 참고해보자...
가능한 cuda와 OS 버전의 조합은 여기를 참고 필자는 cuda 12.1과 우분투 20.04를 선택했고 이 경우 docker run 명령은 이렇게 내릴 수 있다.
$ docker run --gpus=all -it nvidia/cuda:12.1.0-runtime-ubuntu20.04 bash
--gpus
인수는 GPU 디바이스를 컨테이너에 추가하는 명령이고, all
로 설정하면 모든 장치를 컨테이너에 추가한다. docker docs
$ docker run --gpus=all -it nvidia/cuda:12.1.0-runtime-ubuntu20.04 bash
Unable to find image 'nvidia/cuda:12.1.0-runtime-ubuntu20.04' locally
12.1.0-runtime-ubuntu20.04: Pulling from nvidia/cuda
96d54c3075c9: Pull complete
755e535b54a3: Pull complete
24ff69e0a1e4: Pull complete
76a627ca5e65: Pull complete
35817692a87e: Pull complete
84b6a42e847a: Pull complete
4639b7cd68e5: Pull complete
a7bc10701a5b: Pull complete
7d32a9230f8f: Pull complete
Digest: sha256:c1869c30f46fff478a37ed58d9dace7e08519541274f03424d0b78bd35b2c73a
Status: Downloaded newer image for nvidia/cuda:12.1.0-runtime-ubuntu20.04
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error running hook #0: error running hook: exit status 1, stdout: , stderr: Auto-detected mode as 'legacy'
nvidia-container-cli: initialization error: load library failed: libnvidia-ml.so.1: cannot open shared object file: no such file or directory: unknown.
ERRO[0075] error waiting for container:
필자의 경우 nvidia-container-cli: initialization error: load library failed: libnvidia-ml.so.1: cannot open shared object file: no such file or directory: unknown 오류가 뜨며 컨테이너 실행이 되지 않는 오류가 발생했다.
무슨 이유인지는 모르겠으나 해당 이미지를 기반으로 하는 Dockerfile을 작성한 다음 빌드를 진행한 이미지는 잘 작동했다...