Win11 WSL2/DevContainer を GPU が動くように改修

Dockerfile

https://raw.githubusercontent.com/kagyuu/Python3-devcontainer/gpu/.devcontainer/Dockerfile

FROM nvidia/cuda:11.7.1-devel-ubuntu22.04

ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Tokyo

# update the ubuntu os image and install mandatory libs.
RUN apt-get update && apt-get upgrade -y && \
    apt-get install -y build-essential libbz2-dev libdb-dev \
        libreadline-dev libffi-dev libgdbm-dev liblzma-dev \
        libncursesw5-dev libsqlite3-dev libssl-dev \
        zlib1g-dev uuid-dev tk-dev \
        sudo wget curl apt-utils locales lsb-release bash-completion && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

ARG PYTHON_VERSION
ARG PYTHON_REVISION
RUN wget https://www.python.org/ftp/python/${PYTHON_VERSION}.${PYTHON_REVISION}/Python-${PYTHON_VERSION}.${PYTHON_REVISION}.tgz && \
    tar -xf Python-${PYTHON_VERSION}.${PYTHON_REVISION}.tgz && \
    cd Python-${PYTHON_VERSION}.${PYTHON_REVISION} && \
    ./configure --enable-optimizations && \
    make -j $(nproc) | tee build.log && \
    sudo make altinstall

RUN /usr/local/bin/pip${PYTHON_VERSION} install --upgrade pip && \
    /usr/local/bin/pip${PYTHON_VERSION} install autopep8 black yapf bandit flake8 mypy pycodestyle pydocstyle pylint

# Options
RUN apt-get update && \
    apt-get install -y \
        git vim tree htop iputils-ping iproute2 \
        intel-mkl \
        postgresql-client && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# for the numpy/scipy running on the intel processors.
RUN update-alternatives --set libblas.so.3-x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/libmkl_rt.so && \
    update-alternatives --set libblas.so-x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/libmkl_rt.so

# create vscode user
ARG USERNAME=vscode
ARG GROUPNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN groupadd -g 1000 ${GROUPNAME} && \
    useradd -m -s /bin/bash -u ${USER_UID} -g ${USER_GID} ${USERNAME} && \
    echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} && \
    chmod 0440 /etc/sudoers.d/${USERNAME} && \
    localedef -f UTF-8 -i ja_JP ja_JP.UTF-8

# install poerty for vscode user
USER vscode
ARG WORKDIR
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python${PYTHON_VERSION} -
RUN echo "export PATH=/home/vscode/.local/bin:$PATH" >> /home/vscode/.bashrc
RUN /home/vscode/.local/bin/poetry completions bash | sudo tee /etc/bash_completion.d/poerty.bash-completion > /dev/null
RUN /home/vscode/.local/bin/poetry config cache-dir /workspaces/${WORKDIR}/.cache

devcontainer.json

https://raw.githubusercontent.com/kagyuu/Python3-devcontainer/gpu/.devcontainer/devcontainer.json

{
	"name": "Python 3",
	"build": {
		"dockerfile": "Dockerfile",
		"context": "..",
		"args": {
			"WORKDIR" : "Python3-devcontainer",
			"PYTHON_VERSION" : "3.11",
			"PYTHON_REVISION" : "3"
		}
	},

	// Configure tool-specific properties.
	"customizations": {
		// Configure properties specific to VS Code.
		"vscode": {
			// Set *default* container specific settings.json values on container create.
			"settings": { 
				"python.defaultInterpreterPath": "/usr/local/bin/python3.11",
				"python.linting.enabled": true,
				"python.linting.pylintEnabled": true,
				"python.formatting.autopep8Path": "/usr/local/bin/autopep8",
				"python.formatting.blackPath": "/usr/local/bin/black",
				"python.formatting.yapfPath": "/usr/local/bin/yapf",
				"python.linting.banditPath": "/usr/local/bin/bandit",
				"python.linting.flake8Path": "/usr/local/bin/flake8",
				"python.linting.mypyPath": "/usr/local/bin/mypy",
				"python.linting.pycodestylePath": "/usr/local/bin/pycodestyle",
				"python.linting.pydocstylePath": "/usr/local/bin/pydocstyle",
				"python.linting.pylintPath": "/usr/local/bin/pylint"
			},
			
			// Add the IDs of extensions you want installed when the container is created.
			"extensions": [
				"ms-python.python",
				"ms-python.vscode-pylance",
				"ms-azuretools.vscode-docker", // To avoid the vscode on the devcontaier recommends it.
				"oderwat.indent-rainbow"
			]
		}
	},

	"runArgs" : [
		"--runtime=nvidia",
		"--gpus","all",
		"--add-host=host.docker.internal:host-gateway"
	],

	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// 8888 : jupyter notebook
	"forwardPorts": [8888],

	// Use 'postCreateCommand' to run commands after the container is created.
	// "postCreateCommand": "pip3 install --user -r requirements.txt",

	// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
	"remoteUser": "vscode"
}


Windows11


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS   sitemap
Last-modified: 2023-06-02 (金) 00:49:29 (563d)
Short-URL: http://at-sushi.com/pukiwiki/pukiwiki.php?cmd=s&k=b73c10f523
ISBN10
ISBN13
9784061426061