In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
The main content of this article is to explain "what is the method of Go containerization". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what is the method of Go containerization"?
Demonstration project
Package mainimport ("github.com/gin-gonic/gin"net/http") func main () {r: = gin.Default () r.GET ("/", func (c * gin.Context) {c.JSON (http.StatusOK, gin.H {"code": 0, "message": "success", "data": "hello world" }) r.GET ("/ hello", func (c * gin.Context) {c.JSON (http.StatusOK, gin.H {"code": 0, "message": "success", "data": "world",})}) r.GET ("/ ping") Func (c * gin.Context) {c.JSON (http.StatusOK, gin.H {"code": 0, "message": "success", "data": "pong" }) r.Run (": 8080")} DockerFileFROM registry.cn-beijing.aliyuncs.com/baxiang/golang:1.14 as buildENV GO111MODULE=offENV GOBUILDPATH=github.com/baxiang/hello-worldRUN mkdir-p / go/src/$ {GOBUILDPATH} COPY. / / go/src/$ {GOBUILDPATH} RUN cd / go/src/$ {GOBUILDPATH} & & CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go install-vFROM alpine as debugWORKDIR / hello-wordldCOPY-- from=build / go/bin/hello-world. / Hello-worldEXPOSE 8080CMD [". / hello-world"] docker-compose
The go project builds a docker image based on alpine, and always reports standard_init_linux.go:211: exec user process caused "no such file or directory" when starting the container.
Dynamic linking is not supported on miniature mirror alpine. The default go uses static links, and dynamic compilation is used by default in docker's golang environment.
If you want to use docker compilation + alpine deployment, you can do this by disabling cgo set CGO_ENABLED=0.
If you want to use cgo, you can use go build-- ldflags "--extldflags-static" to make gcc use static compilation.
At this point, I believe you have a deeper understanding of "what is the method of Go containerization". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.