add files

This commit is contained in:
2025-03-15 20:08:48 +08:00
parent 00da211880
commit f4f28ca3f4
7 changed files with 258 additions and 0 deletions

24
golang-dev/Dockerfile Normal file
View File

@ -0,0 +1,24 @@
# 选择基础镜像,使用 Ubuntu 最新版本
#FROM ubuntu:latest
FROM --platform=linux/amd64 ubuntu:latest
# 设置时区,避免交互式输入
ENV DEBIAN_FRONTEND=noninteractive
# 安装基础工具和 Golang
RUN apt-get update && apt-get install -y \
curl wget git vim build-essential \
&& rm -rf /var/lib/apt/lists/*
# 安装 Golang
RUN wget https://go.dev/dl/go1.22.2.linux-amd64.tar.gz && \
tar -C /usr/local -xzf go1.22.2.linux-amd64.tar.gz && \
rm go1.22.2.linux-amd64.tar.gz
# 配置 Golang 环境变量
ENV PATH="/usr/local/go/bin:${PATH}"
ENV GOPATH="/root/go"
ENV PATH="${GOPATH}/bin:${PATH}"
# 设置默认命令,进入 shell
CMD ["/bin/bash"]

View File

@ -0,0 +1,41 @@
---
services:
golang-dev:
image: golang-dev:latest # 指定了镜像名
build:
context: .
dockerfile: Dockerfile
container_name: golang-dev
restart: unless-stopped
networks:
- devops # 你之前创建的 devops 网络
ports:
- "2080:80"
volumes:
- ~/Documents/codes/golang:/root/projects # 挂载git工程目录
# mkdir -p ~/dockers/golang-dev/{hostdir,go-mod,.ssh}
# touch ~/dockers/golang-dev/.gitconfig
- ~/dockers/golang-dev/hostdir:/root/hostdir # 挂载一个通用的主机目录
- ~/dockers/golang-dev/go-mod:/root/go # 挂载一个go pkg 目录
- ~/dockers/sharedata:/root/sharedata # 挂载一个docker之间共享的目录
- ~/dockers/golang-dev/.ssh:/root/.ssh # 允许 SSH 访问 git 仓库
- ~/dockers/golang-dev/.gitconfig:/root/.gitconfig # 共享 Git 配置文件
environment:
- TZ=Asia/Shanghai # 设置时区
stdin_open: true
tty: true
# docker-compose build # 重新构建镜像
# docker-compose up -d # 运行最新的容器
# docker-compose up -d --build
# docker image prune -f # 批量删除未被容器使用的旧镜像
# docker image prune -a -f # 删除所有未使用的镜像(包括 dangling 和 unreferenced 镜像)
networks:
devops:
external: true # 你已有的 devops 网络