dev containers plugins for vscode构建虚拟开发环境

0. 需求说明

自用笔记本构建一套开发环境,用docker 虚拟插件 dev containers,实现开发环境的构建,我想构建一套LLMs的环境,由于环境配置太多,不想污染本地环境,所以选择隔离技术

1. 环境准备

  • vscode
  • docker

2. 步骤

2.1 vscode 安装插件

  • Dev Containers
  • Remote Development

2.2 项目根目录下创建.devcontainer文件

目录结构
目录结构

2.2.1 直接用镜像构建环境

devcontainers.json
VS Code Dev Containers官方文档
字段说明【具体字段参见官方网站字段描述】:
1.name:dev container 名称
2.image:镜像名称
3. customizations:在支持的工具中定义
4. build:dockerfile 构建时需要配置
5. context:构建的位置上下文,默认. 当前目录,.. 表示上级目录
6. dockerfile: dockerfile 文件

{
  "name": "LLMs From Scratch",
  "image": "llms-from-scratch:0.1",
  "customizations": {
    "vscode": {
      "extensions": [
        "ms-python.python",
        "ms-azuretools.vscode-docker",
        "ms-toolsai.jupyter",
        "yahyabatulu.vscode-markdown-alert",
        "tomoki1207.pdf",
        "mechatroner.rainbow-csv"
      ]
    }
  }
}

2.2.2 用Dockefile构建镜像

devcontainers.json

{
  "name": "LLMs From Scratch",
  "build": {
    "context": "..",
    "dockerfile": "Dockerfile"
  },
  "customizations": {
    "vscode": {
      "extensions": [
        "ms-python.python",
        "ms-azuretools.vscode-docker",
        "ms-toolsai.jupyter",
        "yahyabatulu.vscode-markdown-alert",
        "tomoki1207.pdf",
        "mechatroner.rainbow-csv"
      ]
    }
  }
}

Dockerfile

FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime

RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y rsync && \
    apt-get install -y git && \
    apt-get install -y curl && \
    rm -rf /var/lib/apt/lists/*

COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

requirements 环境需要的配置信息

torch >= 2.0.1       
jupyterlab >= 4.0    
tiktoken >= 0.5.1    
matplotlib >= 3.7.1  
tensorflow >= 2.15.0 
tqdm >= 4.66.1       
numpy >= 1.25, < 2.0  
pandas >= 2.2.1       
psutil >= 5.9.5     

3.启动环境

Command + Shift + P
输入:Dev Containers: Rebuild and Reopen in Container

启动截图

启动成功截图
环境启动成功截图

4. 关闭环境

File —>close remote connection

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值