From 8b10207790a827776d0eec1506b6a99dfffcf7ec Mon Sep 17 00:00:00 2001 From: yumaojun03 <719118794@qq.com> Date: Sun, 28 Dec 2025 18:33:35 +0800 Subject: [PATCH] =?UTF-8?q?```=20feat(devcontainer):=20=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0Dockerfile=E6=9E=84=E5=BB=BA=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将devcontainer.json配置从使用基础镜像和Features改为使用本地Dockerfile构建 - 更新README.md文档,说明已改为基于官方golang:1.25-bookworm镜像的本地构建方式 - 修改备注部分,指示用户在Dockerfile中添加额外工具而非在devcontainer.json中配置 ``` --- day01/devcontainer/.devcontainer/Dockerfile | 16 ++++++++++++++++ .../devcontainer/.devcontainer/devcontainer.json | 8 ++------ day01/devcontainer/README.md | 4 ++-- 3 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 day01/devcontainer/.devcontainer/Dockerfile diff --git a/day01/devcontainer/.devcontainer/Dockerfile b/day01/devcontainer/.devcontainer/Dockerfile new file mode 100644 index 0000000..e2f743c --- /dev/null +++ b/day01/devcontainer/.devcontainer/Dockerfile @@ -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 diff --git a/day01/devcontainer/.devcontainer/devcontainer.json b/day01/devcontainer/.devcontainer/devcontainer.json index 5355bf6..146e0d9 100644 --- a/day01/devcontainer/.devcontainer/devcontainer.json +++ b/day01/devcontainer/.devcontainer/devcontainer.json @@ -1,11 +1,7 @@ { "name": "Go Dev Container (demo)", - "image": "mcr.microsoft.com/devcontainers/base:ubuntu", - "features": { - "ghcr.io/devcontainers/features/common-utils:2": {}, - "ghcr.io/devcontainers/features/go:1": { - "version": "1.25" - } + "build": { + "dockerfile": ".devcontainer/Dockerfile" }, "remoteUser": "vscode", "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", diff --git a/day01/devcontainer/README.md b/day01/devcontainer/README.md index 7db051b..40b6825 100644 --- a/day01/devcontainer/README.md +++ b/day01/devcontainer/README.md @@ -7,7 +7,7 @@ - 打开文件夹:在 VS Code 中打开 `day01/devcontainer` 目录。 - 重新在容器中打开:命令面板运行 “Dev Containers: Reopen in Container”。 - 首次启动会执行依赖下载:`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`。 @@ -24,7 +24,7 @@ - 断点与变量查看可在容器内正常使用。 ### 备注 -- 如需额外工具(如 `golangci-lint` 的安装或 `dlv` 调试器),可在 `.devcontainer/devcontainer.json` 中增加特性或 `postCreateCommand`。 +- 如需额外工具(如 `golangci-lint` 的安装或 `dlv` 调试器),可在 `.devcontainer/Dockerfile` 或 `postCreateCommand` 中添加。 # devcontainer demo 工程