```
feat(devcontainer): 改用本地Dockerfile构建开发环境 - 将devcontainer.json配置从使用基础镜像和Features改为使用本地Dockerfile构建 - 更新README.md文档,说明已改为基于官方golang:1.25-bookworm镜像的本地构建方式 - 修改备注部分,指示用户在Dockerfile中添加额外工具而非在devcontainer.json中配置 ```
This commit is contained in:
parent
8e9bf583c5
commit
8b10207790
16
day01/devcontainer/.devcontainer/Dockerfile
Normal file
16
day01/devcontainer/.devcontainer/Dockerfile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# Dev Container built locally to avoid registry blockers
|
||||||
|
# Use official Golang image (Debian bookworm) for Go 1.25
|
||||||
|
FROM golang:1.25-bookworm
|
||||||
|
|
||||||
|
# Install essentials
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends \
|
||||||
|
git sudo ca-certificates curl unzip \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Create vscode user
|
||||||
|
RUN useradd -m -s /bin/bash vscode \
|
||||||
|
&& echo "vscode ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-vscode \
|
||||||
|
&& chmod 0440 /etc/sudoers.d/90-vscode
|
||||||
|
|
||||||
|
WORKDIR /workspaces
|
||||||
@ -1,11 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Go Dev Container (demo)",
|
"name": "Go Dev Container (demo)",
|
||||||
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
|
"build": {
|
||||||
"features": {
|
"dockerfile": ".devcontainer/Dockerfile"
|
||||||
"ghcr.io/devcontainers/features/common-utils:2": {},
|
|
||||||
"ghcr.io/devcontainers/features/go:1": {
|
|
||||||
"version": "1.25"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"remoteUser": "vscode",
|
"remoteUser": "vscode",
|
||||||
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
|
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
- 打开文件夹:在 VS Code 中打开 `day01/devcontainer` 目录。
|
- 打开文件夹:在 VS Code 中打开 `day01/devcontainer` 目录。
|
||||||
- 重新在容器中打开:命令面板运行 “Dev Containers: Reopen in Container”。
|
- 重新在容器中打开:命令面板运行 “Dev Containers: Reopen in Container”。
|
||||||
- 首次启动会执行依赖下载:`postCreateCommand` 会在 `demo/` 下执行 `go mod download`。
|
- 首次启动会执行依赖下载:`postCreateCommand` 会在 `demo/` 下执行 `go mod download`。
|
||||||
- 镜像说明:使用 `mcr.microsoft.com/devcontainers/base:ubuntu`,通过 Dev Containers Feature 安装 Go(版本 1.25)。
|
- 已改为本地 Dockerfile 构建:基于官方 `golang:1.25-bookworm`,避免 MCR/GHCR 拉取受限。
|
||||||
|
|
||||||
### 容器内开发
|
### 容器内开发
|
||||||
- 代码位置:`/workspaces/<当前打开的文件夹>/demo`。
|
- 代码位置:`/workspaces/<当前打开的文件夹>/demo`。
|
||||||
@ -24,7 +24,7 @@
|
|||||||
- 断点与变量查看可在容器内正常使用。
|
- 断点与变量查看可在容器内正常使用。
|
||||||
|
|
||||||
### 备注
|
### 备注
|
||||||
- 如需额外工具(如 `golangci-lint` 的安装或 `dlv` 调试器),可在 `.devcontainer/devcontainer.json` 中增加特性或 `postCreateCommand`。
|
- 如需额外工具(如 `golangci-lint` 的安装或 `dlv` 调试器),可在 `.devcontainer/Dockerfile` 或 `postCreateCommand` 中添加。
|
||||||
|
|
||||||
# devcontainer demo 工程
|
# devcontainer demo 工程
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user