This is a creation in Article, where the information may have evolved or changed.
Build a MySQL Environment
Mysql.app
docker run --net=host -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=letchat -d hub.c.163.com/library/mysql:latest
1. Compile and run the Golang program in the current directory via the container (dependencies need to be downloaded to the current directory vendor first)
Gobuild.app
docker run --net=bridge --rm -v $PWD:/go/src/app -w /go/src/app hub.c.163.com/library/golang:latest go build -v
2. Use Docker to build the image, run a container on this image, run the Golang program using that container
Dockerfile
FROM hub.c.163.com/library/golang:latestWORKDIR /go/src/appCOPY . .#RUN go-wrapper download # \"go get -d -v ./...\"RUN go-wrapper install # \"go install -v ./...\"CMD ["sh","-c","/go/bin/app"]
Gorun.app
# build image app# docker build -t app:latest .# set envexport GIN_MODE=release# make the containerdocker run --net=host -it -d app:latest
Choose 1 of 2 ways. The first one is to generate an app directly locally, which can be run directly./app. The second is to run the app inside the container, but the network port uses the host's port, which is equivalent to running directly on the local computer.