Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of containerization of Go

2025-03-31 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report