如何使用 vscode devcontainer 开发

第一步 安装 dev container 插件

第二步 创建一个 .devcontainer/devcontainer.json 文件

  • 创建 .devcontainer/devcontainer.json 文件
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node
{
	"name": "my-env",
	// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
	"image": "alpine:3.16.3",

	// Features to add to the dev container. More info: https://containers.dev/features.
	// "features": {},

	// Configure tool-specific properties.
	"customizations": {
		// Configure properties specific to VS Code.
		"vscode": {
			"extensions": [
				"streetsidesoftware.code-spell-checker"
			]
		}
	},

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

	// Use 'portsAttributes' to set default properties for specific forwarded ports. 
	// More info: https://containers.dev/implementors/json_reference/#port-attributes
	"portsAttributes": {
		"9000": {
			"label": "Hello Remote World",
			"onAutoForward": "notify"
		}
	},

	// Use 'postCreateCommand' to run commands after the container is created.
	"postCreateCommand": "echo ok container started "

	// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
	// "remoteUser": "root"
}

第三步 Open Folder in Container

  1. 菜单栏执行 View – Command Palette (command + shift + p)
  2. 执行 Dev Containers: Open Folder in Container

后续再次启动 vscode 会运行之前的 docker,里面安装的内容都是还在里面的

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

上一篇:
下一篇: