diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..713cb20 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,107 @@ +FROM pytorch/pytorch:2.2.2-cuda12.1-cudnn8-devel + +# ==================================== +# Build Arguments +# ==================================== +# Set the timezone (Default: Asia/Seoul) +ARG TIMEZONE=Asia/Seoul +# Set the Python version (Default: 3.11.9) +ARG PYTHON_VERSION=3.11.9 +# Set the Ubuntu APT mirror (Default: http://archive.ubuntu.com/ubuntu) +ARG UBUNTU_APT_MIRROR=http://archive.ubuntu.com/ubuntu +# Set the user and group (Default: ubuntu) +ARG USER=ubuntu +ARG GROUP=ubuntu +# Set the user ID and group ID (Default: 1000) +ARG UID=1000 +ARG GID=1000 + +# ==================================== +# Environment Variables +# ==================================== +# VSCode Server - Password +ENV PASSWORD=password +# SSH - Public Key (Optional - If you want to use the SSH) +ENV SSH_PUBLIC_KEY="" +# User home directory (Default: /home/ubuntu) +ENV HOME=/home/${USER} +# Workspace directory (Default: /workspace) +ENV WORKSPACE=/workspace +# VSCode Server directory (Default: /workspace/.code-server) +ENV VSCODE_HOME=${WORKSPACE}/.code-server + +# Set the timezone +RUN ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime + +# Change the apt source +RUN sed -i 's|http://.*.ubuntu.com/ubuntu/|${UBUNTU_APT_MIRROR}|g' /etc/apt/sources.list +RUN apt update + +# Install dependencies +RUN apt update +RUN apt install -y \ + dumb-init \ + sudo \ + curl \ + htop \ + git \ + nano \ + wget \ + openssh-server \ + unzip \ + software-properties-common \ + build-essential + +# Install Python3.11 +RUN mkdir -p /tmp/python && curl -L https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz | tar -xJ -C /tmp/python +RUN cd /tmp/python/Python-${PYTHON_VERSION} && ./configure --enable-optimizations && make altinstall && rm -rf /tmp/python + +# Install Python packages +COPY ./requirements.txt /tmp/requirements.txt +RUN pip install --upgrade pip && pip install -r /tmp/requirements.txt && rm /tmp/requirements.txt + +# Create a non-root user +RUN groupadd -g ${GID} ${GROUP} && \ + useradd -m -s /bin/bash -u ${UID} -g ${GID} ${USER} && \ + usermod -aG sudo ${USER} && \ + echo "${USER} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + +RUN mkdir -p ${HOME}/.ssh +RUN touch ${HOME}/.ssh/authorized_keys +RUN chown -R ${UID}:${GID} ${HOME}/.ssh +RUN chmod 700 ${HOME}/.ssh +RUN chmod 600 ${HOME}/.ssh/authorized_keys + +# Disable password authentication +RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config + +# Clean up +RUN apt clean && rm -rf /var/lib/apt/lists/* + +# Set the workspace +RUN mkdir -p ${WORKSPACE} +RUN chown -R ${UID}:${GID} ${WORKSPACE} ${HOME} + +USER ${USER} +WORKDIR ${WORKSPACE} + +# Install VSCode server +RUN mkdir -p ${VSCODE_HOME} +RUN curl -fsSL https://code-server.dev/install.sh | sudo sh + +COPY ./entrypoint.sh /entrypoint.sh + +EXPOSE 22 +EXPOSE 443 + +ENTRYPOINT [ \ + "/entrypoint.sh", \ + "code-server", \ + "--bind-addr", "0.0.0.0:443", \ + "--extensions-dir", "${VSCODE_HOME}/extensions", \ + "--user-data-dir", "${VSCODE_HOME}/data", \ + "--disable-telemetry", \ + "--disable-update-check", \ + "--disable-crash-reporter", \ + "." \ +] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..026a74b --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +echo "${SSH_PUBLIC_KEY}" > ~/.ssh/authorized_keys + +if [ ! -z "$SSH_PUBLIC_KEY" ]; then + sudo service ssh start; +fi + +dumb-init "$@" \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..853050a --- /dev/null +++ b/readme.md @@ -0,0 +1,59 @@ +# PyTorch VSCode Server with CUDA + +Docker images for machine learning development environments using CUDA and PyTorch and for remote development via VSCode and SSH server + +## Features + +- CUDA 12.1 +- Python 3.11.9 +- PyTorch 2.2.2 +- Code Server +- SSH Server +- \+ Other tools (e.g. git, wget, curl, unzip, etc.) +- \+ Python packages (e.g. numpy, pandas, matplotlib, tensorboard, etc.) + +## Usage + +```bash +docker run -d \ + -p 5443:443 \ + -p 5022:22 \ + --gpus '"device=0"' \ + -e PASSWORD="your_vscode_password" \ + --name pytorch-vscode-server \ + ghcr.io/Soju06/pytorch-vscode-server:2.2.2-cuda12.1 +``` + +- Access VSCode Server: `https://localhost:5443` +- SSH: `ssh ubuntu@localhost -p 5022 -i ~/.ssh/id_rsa` (only key-based authentication, If you do not set up `SSH_PUBLIC_KEY`, SSH Server will not run.) + +If you want to use SSH Server, you need to set `SSH_PUBLIC_KEY` environment variable. + +```bash +docker run -d \ + -p 5443:443 \ + -p 5022:22 \ + --gpus '"device=0"' \ + -e PASSWORD="your_vscode_password" \ + -e SSH_PUBLIC_KEY="$(cat ~/.ssh/id_rsa.pub)" \ + --name pytorch-vscode-server \ + ghcr.io/Soju06/pytorch-vscode-server:2.2.2-cuda12.1 +``` + +### Build Arguments + +- `TIMEZONE`: Set the timezone. Default is `Asia/Seoul` +- `PYTHON_VERSION`: Set the Python version. Default is `3.11.9` +- `UBUNTU_APT_MIRROR`: Set the Ubuntu apt mirror. Default is `http://archive.ubuntu.com/ubuntu` +- `USER`: Set the user name. Default is `ubuntu` +- `GROUP`: Set the group name. Default is `ubuntu` +- `UID`: Set the user id. Default is `1000` +- `GID`: Set the group id. Default is `1000` + +### Environment Variables + +- `PASSWORD`: Set the password for VSCode Server. Default is `password` +- `SSH_PUBLIC_KEY`: Set the public key for SSH Server. Default is empty +- `HOME`: Set the home directory. Default is `/home/ubuntu` +- `WORKSPACE`: Set the workspace directory. Default is `/workspace` +- `VSCODE_HOME`: Set the VSCode Server home directory. Default is `/workspace/.code-server` diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..bc70ab3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +numpy==1.26.4 +pandas==2.2.2 +matplotlib==3.8.4 +scikit-learn==1.4.2 +opencv-python==4.9.0.80 +jupyterlab==4.1.6 +pillow==10.3.0 +tensorboard==2.16.2 \ No newline at end of file