3
0

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 1 year has passed since last update.

NGC CatalogのPyTorchコンテナイメージを使う

Posted at

参考

開発用コンテナ

コンテナイメージはNGC Catalogから選ぶ。

Dockerfile
FROM nvcr.io/nvidia/pytorch:22.04-py3

ARG PROXY_URL

RUN apt-get update \
    # SSHサーバをインストール
    && apt-get install -q -y ssh \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* \
    # SSHサーバが動作するために必要なsockファイルが配置されるディレクトリを用意
    && mkdir /var/run/sshd \
    # rootでログインできるようにするため、パスワードを設定(ただしこのパスワードは使いません)
    && echo 'root:password' | chpasswd \
    # パスワードでのログインをできないようにする
    && sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin prohibit-password/' /etc/ssh/sshd_config # 

# SSHで使用する公開鍵をここでコピーする
WORKDIR /
COPY id_rsa.pub /root/.ssh/authorized_keys
# SSHポートを公開する(Docker Composeで別のポートにバインドするので22番ポートのまま)
EXPOSE 22  # 必要?

# その他開発に必要なプログラムのインストールなど
RUN apt-get update

# conda仮想環境作成
RUN conda create -n myenv python=3.9
# 仮想環境の activate 
ENV CONDA_DEFAULT_ENV myenv
# コンテナログイン用設定
RUN echo "conda activate myenv" >> ~/.bashrc
RUN echo "PATH=${PATH}:/opt/conda/envs/myenv/bin" >> ~/.bashrc

# ライブラリのインストール
RUN pip install pyanom

#.bash_profileを作成し、.bashrcを読み込む(シェルスクリプト)
RUN echo "if [ -f ~/.bashrc ]; then  . ~/.bashrc;  fi" >> ~/.bash_profile
# 環境変数の書き込み
RUN echo "HTTP_PROXY=${PROXY_URL}" >> ~/.bashrc
RUN echo "http_proxy=${PROXY_URL}" >> ~/.bashrc
RUN echo "HTTPS_PROXY=${PROXY_URL}" >> ~/.bashrc
RUN echo "https_proxy=${PROXY_URL}" >> ~/.bashrc

CMD ["/usr/sbin/sshd", "-D"]
docker-compose.yml
version: '2.3'
services:
  worker:
    build:
      context: ./
      args:
      - PROXY_URL=$PROXY_URL
    environment:
    - NVIDIA_VISIBLE_DEVICES=all
    - NVIDIA_DRIVER_CAPABILITIES=all
    container_name: dev
    ports:
    - "48881:22"
    volumes:
    - ${PWD}:/work
    runtime: nvidia
    working_dir: /work
.env
PROXY_URL=http://user:pass@proxy_url:port

jupyter用コンテナ

Dockerfile
FROM nvcr.io/nvidia/pytorch:22.04-py3

ADD ./jupyter_notebook_config.py /root/.jupyter/jupyter_notebook_config.py

# RUN pip install ...
docker-compose.yml
version: '2.3'
services:
  jupyter:
    build:
      context: ./
    container_name: dev-jupyter
    ports:
    - "21000:8888"
    volumes:
    - ${PWD}:/work
    runtime: nvidia
    working_dir: /work
    command: jupyter notebook 
jupyter_notebook_config.py
c = get_config()
c.NotebookApp.ip = '0.0.0.0'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888
c.NotebookApp.token = ''
3
0
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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?