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-runtimeRUN 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