go: downloading github.com/go-playground/locales v0.14.1[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production. - using env: export GIN_MODE=release - using code: gin.SetMode(gin.ReleaseMode)[GIN-debug] GET /albums --> main.getAlbums (3 handlers)[GIN-debug] GET /albums/:id --> main.getAlbumByID (3 handlers)[GIN-debug] POST /albums --> main.postAlbums (3 handlers)[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.Please check https://github.com/gin-gonic/gin/blob/master/docs/doc.md#dont-trust-all-proxies for details.[GIN-debug] Listening and serving HTTP on 0.0.0.0:8080[GIN] 2026/06/03 - 11:19:14 | 404 | 1.219µs | 172.18.0.1 | GET "/"[GIN] 2026/06/03 - 11:19:14 | 404 | 778ns | 172.18.0.1 | GET "/favicon.ico"[GIN] 2026/06/03 - 11:19:45 | 200 | 147.412µs | 172.18.0.1 | GET "/albums"
在宿主机测试 API
打开另一个终端,执行:
Bash
curlhttp://localhost:8080/albums
或直接在浏览器访问 http://localhost:8080/albums。
📸 浏览器显示 JSON 数据,如图4
🧹 九、常用管理命令
操作
命令
启动开发容器
cd ~/code/go-gin-learning && docker compose up -d
停止容器
docker compose down
重新构建镜像
docker compose build --no-cache
查看日志
docker compose logs -f
进入容器
docker exec -it go-gin-learning sh
重启 MySQL/Redis(若需要)
cd ~/docker/services && docker compose restart
⚠️ 十、避坑指南
10.1 容器内 git 缺失导致 go run 失败
现象:
Plaintext
unable to resolve git version: exec: "git": executable file not found in $PATH
[…] you have read my previous blog post (such as “Setting Up a Basic Environment with Docker Compose + Go 1.26.4 on Ubuntu 26.04”), you can consider this one the “next chapter”—stringing everything together from […]
评论
2 条对“Ubuntu 26.04 + Docker 搭建 Go Gin 开发环境(全记录)”的回复
[…] […]
[…] you have read my previous blog post (such as “Setting Up a Basic Environment with Docker Compose + Go 1.26.4 on Ubuntu 26.04”), you can consider this one the “next chapter”—stringing everything together from […]