Files
test-6/.devcontainer/Dockerfile
panshuxiao adefecc0bd init
2025-04-06 19:52:57 +08:00

36 lines
952 B
Docker

FROM golang:1.21-bullseye
# 安装基本工具
RUN apt-get update && apt-get install -y \
git \
curl \
wget \
vim \
sudo \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# 创建一个非root用户
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME
# Go工具设置
ENV GOPATH=/go
ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" "$GOPATH/pkg" \
&& chmod -R 777 "$GOPATH" \
&& go install -v golang.org/x/tools/gopls@latest \
&& go install -v github.com/go-delve/delve/cmd/dlv@latest \
&& go install -v honnef.co/go/tools/cmd/staticcheck@latest
# 设置工作目录
WORKDIR /workspace
# 使用创建的非root用户
USER $USERNAME