Preface
Recently, on Ubuntu 26.04, I tried using the Trae CN editor along with Docker containers to develop a Go + Gin project (go-gin-learning). I ran into a few pitfalls along the way, but I managed to get a fairly smooth workflow up and running. This article is a complete record of that process, which I hope will help others facing similar issues.
If 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 code commits to running in a container.
1. Preparations on the Host Machine
1.1 Install Git and Configure User Information
First, ensure Git is installed on the host machine, then set your global username and email (this information will be included in every commit):
git config --global user.name "shuijingwan"
git config --global user.email "shuijingwanwq@163.com"Verify the configuration:
git config --global user.name
git config --global user.email1.2 Configure GitHub Authentication (Using a Token)
Since 2021, GitHub no longer supports password authentication, so you need to generate a Personal Access Token.
- Log in to GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)
- Click Generate new token (classic)
- Check the
repopermission, and copy the token once it is generated (it is only displayed once) - Run the following command in the host machine’s terminal:
git push origin mainWhen prompted for your username, enter your GitHub username, and paste the token you just copied for the password. Once successful, Git will remember the authentication credentials (if a credential helper is configured).
1.3 Install Go (Host Machine)
To ensure that code completion and syntax jumping work properly in Trae CN, you need to install Go on the host machine. I chose to install it via APT because it is simple and hassle-free:
sudo apt update
sudo apt install golang-go -y
go versionOutput: go version go1.26.0 linux/amd64
Actually, the system “Software” center also offers a Snap version of Go (see screenshot), but APT is more lightweight and compatible with the Go version inside the container.

1.4 Install the Go Extension in Trae CN
Open the Trae CN extension store, search for Go, find the official extension (published by golang), and install it.

Once installed, press Ctrl+Shift+P, enter Go: Install/Update Tools, check the common tools such as gopls, dlv, and staticcheck from the pop-up list, and click OK.

Wait for the installation to complete, then reload the window.
At this point, the code editing environment on the host machine is ready.

fmt. in main.go should trigger IntelliSense.2. Development Environment Inside the Container
2.1 Let the Container Reuse the Host’s Git Configuration
We want to use the host machine’s username and email when executing git commit inside the container. Modify docker-compose.yml to mount ~/.gitconfig:
volumes:
- ./:/code
- ~/.gitconfig:/root/.gitconfig:roAfter restarting the container, enter it to verify:
docker exec -it go-gin-learning sh
git config --global user.name # 应显示 shuijingwan
git config --global user.email # 应显示 shuijingwanwq@163.com2.2 Fix Slow Go Module Downloads
Initially, running go mod tidy inside the container would always fail or time out because the default proxy goproxy.io is unstable, and the cache gets cleared every time the container is rebuilt.
There are two solutions:
- Set a more stable proxy:
go env -w GOPROXY=https://goproxy.cn,direct - Persist the module cache: Mount a host machine directory to the container’s
/go/pkg/mod
I opted for the latter by adding the following to docker-compose.yml:
volumes:
- ~/go/pkg-mod-go-gin-learning:/go/pkg/modThis way, the dependencies inside the container are stored in a dedicated directory on the host machine, so they won’t be lost even if the container is deleted. When running go mod tidy again, all go: downloading succeeded.
2.3 Run the Gin Service
Execute the following inside the container:
go run main.goSeeing the following output means the service started successfully:
[GIN-debug] Listening and serving HTTP on 0.0.0.0:8080Access http://localhost:8080/albums in a browser; it returns JSON data with a 200 status code.

At this point, in the Trae CN Docker extension panel, you can right-click the container and select Attach Shell to easily open a container terminal.

3. Summary and Standardization Outlook
Current Workflow Summary
- Host machine: Handles Git operations, code editing, and the Go language server (gopls).
- Container: Responsible for running
go runandgo test, with dependency modules persisted via the mounted cache directory. - Trae CN: Provides intelligent completion through the Go extension and attaches to the container terminal via the Docker extension, achieving a workflow of “editing on the host, running in the container.”
Although Dev Containers are temporarily unavailable in Trae CN, through the combination of “host Go + container execution + cache persistence,” we still achieved an efficient and reliable development environment.
(By the way, I did not delete .devcontainer/devcontainer.json because other team members using VS Code might still need it.)
Points for Future Standardization
- Use a Makefile to wrap common commands: Such as
make run,make test, andmake tidyto reduce manual input. - Integrate Air for hot reloading: Install
airinside the container to automatically restart the service after saving a file, boosting development efficiency. - Script the environment configuration: Write the volumes settings, proxy configuration, and dependency installation for
docker-compose.ymlintosetup.shto help new members get onboard quickly. - Consider using Remote – SSH: If the entire team develops on the same server in the future, we could switch to SSH remote development to completely unify the environment.

