18
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Dockerfile】DockerにConda環境を構築し、仮想環境をActivateする

Posted at

CUDAイメージ上に Miniconda or Anaconda 環境を構築し、conda or pip を仮想環境にインストール、アクティベートするところまでをDockerfileで完結させるためのDockerfileを記載します。

実現したいこと

  • CUDAイメージ上にMiniconda(Anaconda)環境を構築
  • Dockerfile内で、任意の仮想環境を作成し、パッケージをインストール
  • Docker run (attach)した際に、Dockerfileに記載した仮想環境下に入る(conda activateする必要がない)

Dockerfile

Dockerfile
FROM nvidia/cuda:11.2.1-devel-ubuntu20.04

RUN apt-get update && apt-get install -y \
    sudo \
    wget \
    vim
WORKDIR /opt

RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
    sh Miniconda3-latest-Linux-x86_64.sh -b -p /opt/miniconda3 && \
    rm -r Miniconda3-latest-Linux-x86_64.sh

ENV PATH /opt/miniconda3/bin:$PATH

COPY <env_file_name>.yml .

RUN pip install --upgrade pip && \
    conda update -n base -c defaults conda && \
    conda env create -n <env_name> -f <env_file_name>.yml && \
    conda init && \
    echo "conda activate <env_name>" >> ~/.bashrc
    
ENV CONDA_DEFAULT_ENV <env_name> && \
    PATH /opt/conda/envs/<env_name>/bin:$PATH

WORKDIR /

CMD ["/bin/bash"]

NVIDIA Containers / Miniconda

NVIDIA CUDA Image 一覧はこちらから
Miniconda 一覧はこちらから

18
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?