Second Brain: Crafted, Curated, Connected, Compounded on 10月02日
VS Code Dev Containers,简化开发环境配置
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

Visual Studio Code Dev Containers扩展允许用户使用Docker容器作为功能齐全的开发环境。通过devcontainer.json文件,VS Code可以定义容器内的工具和运行时堆栈,支持在容器中打开任何文件夹或仓库,并利用VS Code的全部功能。该方案涉及创建devcontainer.json文件来描述容器启动方式,使用Dockerfile进行持久化更改,以及通过Docker Compose配置多个容器。用户可以轻松管理开发环境,确保工具和依赖项的一致性,从而提高开发效率。

🔧 VS Code Dev Containers扩展使用Docker容器作为开发环境,允许用户在容器内打开任何文件夹或仓库,并利用VS Code的全部功能,从而简化开发环境的配置和管理。

📄 devcontainer.json文件定义了容器的启动方式和工具运行时堆栈,用户可以通过该文件指定容器内的开发环境配置,确保不同开发者在不同环境中保持一致性。

🐋 Dockerfile用于持久化容器内的更改,如安装新软件或配置依赖项,使得开发环境的状态可以跨会话保持一致,避免了本地环境差异带来的问题。

🚀 通过Docker Compose,用户可以配置和管理多个容器,实现复杂项目中的不同服务或环境的隔离,提高了开发流程的灵活性和可扩展性。

🔗 Dev Containers扩展与VS Code紧密集成,支持多种配置选项,如端口转发、创建后命令执行等,为用户提供了一个高效、灵活的开发环境解决方案。

The Visual Studio Code Dev Containers extension lets you use a Docker container as a full-featured development environment. It allows you to open any folder or repository inside a container and take advantage of Visual Studio Code’s full feature set.

devcontainer.json file in your project tells VS Code how to access (or create) a development container with a well-defined tool and runtime stack. This container can be used to run an application or to provide separate tools, libraries, or runtimes needed for working with a codebase.

# Path to creating a dev container

In this document, we’ll go through the steps for creating a development (dev) container in VS Code:

    Create a devcontainer.json, which describes how VS Code should start the container and what to do after it connects.Make and persist changes to the dev container, such as installation of new software, through use of a Dockerfile.Configure multiple containers through Docker Compose.As you make changes, build your dev container to ensure changes take effect.

After any of the steps above, you’ll have a fully functioning dev container, and you can either continue to the next step of this tutorial to add more features, or stop and begin working in the dev environment you currently have.

# System Requirements

Local / Remote Host:

You can use Docker with the Dev Containers extension in a few ways, including:

    Docker installed locally.Docker installed on a remote environment.Other Docker compliant CLIs, installed locally or remotely.

You can learn more in the alternative Docker options doc.

Below are some specific ways you can configure Docker on a local or remote host:

    Windows: Docker Desktop 2.0+ on Windows 10 Pro/Enterprise. Windows 10 Home (2004+) requires Docker Desktop 2.3+ and the WSL 2 back-end. (Docker Toolbox is not supported. Windows container images are not supported.)macOSDocker Desktop 2.0+.LinuxDocker CE/EE 18.06+ and Docker Compose 1.21+. (The Ubuntu snap package is not supported.)Remote hosts: 1 GB RAM is required, but at least 2 GB RAM and a 2-core CPU is recommended.

Containers:

    x86_64 / ARMv7l (AArch32) / ARMv8l (AArch64) Debian 9+, Ubuntu 16.04+, CentOS / RHEL 7+x86_64 Alpine Linux 3.9+

Other glibc based Linux containers may work if they have needed Linux prerequisites.

More on Installation.

# devcontainer.json

 1 2 3 4 5 6 7 8 91011121314151617181920212223242526
// For format details, see https://aka.ms/devcontainer.json. For config options, see the// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile{  "name": "Existing Dockerfile",  "build": {      // Sets the run context to one level up instead of the .devcontainer folder.      "context": "..",        // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.       "dockerfile": "../Dockerfile"  }    // Features to add to the dev container. More info: https://containers.dev/features.  // "features": {},  // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [],  // Uncomment the next line to run commands after the container is created.    // "postCreateCommand": "cat /etc/os-release",  // Configure tool-specific properties.    // "customizations": {},    // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.  // "remoteUser": "devcontainer"}

# Example with VSCode

Start CODING IN MINUTES with DevContainers - YouTube

# with Neovim

# Starting Devcontainers

Devpod seems to be able to start Devcontainers. It’s like Github Codespaces, but open-source.

See example in Workspaces.


Origin:
References:
Created 2023-03-15

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Visual Studio Code Dev Containers Docker 开发环境 配置管理
相关文章