Seamlessly migrate from Windows WSL2 to Ubuntu bare metal, build Go development environments based on existing MySQL/Redis containers, and access custom networks.
📌 Preface
I have been learning in Windows 10 + WSL2 before go-gin-learning Project, now to brand new Ubuntu 26.04 system. I hope to continue to use Docker to isolate the sending environment, and at the same time reuse the deployed MySQL 8.0 and Redis 7.2 containers (located on a custom network services_dev-network in).
This article records all the steps of configuring from scratch, including:
System tool check and installation
Docker environment verification
Project code clone
Write a Dockerfile preinstall git
Write docker-compose.yml to access existing networks
Run GIN applications inside the container and test connectivity
常见问题与避坑建议
🧰 1. Preparation: Check the existing tools of the system
Develop the habit of ‘check first, then install’ in Ubuntu, which can avoid repeated operations.
1.1 Check git
git --version
Output example(installed):
git version 2.53.0
If not installed, execute:
sudo apt install git -y
1.2 Check Docker
docker --version
docker compose version
Output example:
Docker version 29.5.2, build 79eb04c
Docker Compose version v5.1.4
💡 If using mysql command, please use --ssl-mode=disabled.
7.5 Test Redis Connections
redis-cli -h redis72 -a myredispass PING
expected output: as shown in Figure 2
PONG
🏃 8. Run the GIN application
Execute inside the container:
go run main.go
Seeing the following log indicates success: as shown in Figure 3
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"
Test API on the host
Open another terminal and execute:
curl http://localhost:8080/albums
or directly in the browser http://localhost:8080/albums.
📸 The browser displays JSON data, as shown in Figure 4
🧹 Nine, common management commands
Operating
Command
Start the development container
cd ~/code/go-gin-learning && docker compose up -d
stop container
Docker compose down
Rebuild the image
docker compose build --no-cache
View logs
docker compose logs -f
Enter the container
docker exec -it go-gin-learning sh
Restart mysql/redis (if required)
cd ~/docker/services && docker compose restart
⚠️ 10. Guide to Pits
10.1 Inside the container git loss leads to go run Failure
Phenomenon:
unable to resolve git version: exec: "git": executable file not found in $PATH
Solve: Install using a custom Dockerfile git, see Chapter 4.
Solve: add in the connection command --ssl=0(mariadb) or --ssl-mode=disabled(mysql).
10.3 Containers cannot access mysql/redis
Reason: The correct network is not added, or the network name is wrong.
Solve:
Confirm docker network ls Middle services_dev-network
Check in docker-compose.yml networks Is the name yesCompletely consistent(including underscore)
in the container ping mysql80 Test
10.4 Host cannot access port 8080
Reason: GIN is listening for 127.0.0.1:8080 instead of 0.0.0.0:8080, causing the port mapping to fail.
Solve: set in the code router.run(':8080') Or router.run('0.0.0.0:8080').
📝 Eleven, summary
Through this practice, I have achieved:
✅ Build a complete Go development environment on Ubuntu 26.04
✅ Take advantage of existing MySQL/Redis containers (independent deployment) and custom networks
✅ Build belt git Go 1.26 Alpine development image
✅ Writing docker-compose.yml mount code and access external network
✅ Successfully run the GIN application inside the container and verify the database connectivity
This ‘Database and code separation container” model is very suitable for multi-project shared infrastructure, saving resources and maintaining environmental consistency.
Next, you can:
In main.go Write the business logic to connect to MySQL/Redis
Use any code editor (such as VS Code, Sublime, etc.) to directly edit the project file, and synchronize in real time in the container after saving
Will docker-compose.yml Join version control to share environment configuration with teammates