In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the implementation of Docker deployment Go basic image, the content is clear, interested partners can learn, I believe it will be helpful after reading.
1. Golang:latest basic image
Mkdir gotesttouch main.gotouch Dockerfile
1. Instance code
Package mainimport ("fmt"log"net/http") func main () {http.HandleFunc ("/", func (writer http.ResponseWriter, request * http.Request) {fmt.Fprint (writer, "Hello World")}) fmt.Println ("3000!") Log.Fatal (http.ListenAndServe (": 3000", nil))}
2. Dockerfile configuration
# Source mirror FROM golang:latest# sets the working directory WORKDIR $GOPATH/src/github.com/gotest# to add the server's go project code to the docker container ADD. $GOPATH/src/github.com/gotest#go builds the executable file RUN go build. # exposing port EXPOSE 300 runs the command ENTRYPOINT for docker [". / gotest"]
3. Package image
Docker build-t gotest. Golang: the latest compilation process, in fact, is to build a go development environment in the container. This source image package is about 800m, which is relatively large.
2. Alpine:latest basic image
The approximate process of using this image is to package the go program into a binary file on the linux machine, and then throw it into the apine environment to execute the compiled file. By default, Go's runtime environment variable CGO_ENABLED=1, which starts cgo by default, allows you to call C code in Go code. CGO is disabled by setting CGO_ENABLED=0. So need to execute: CGO_ENABLED=0 go build. That's it. This basic image package is only 13m, which is very small. # Source mirror FROM alpine:latest# sets the working directory WORKDIR $GOPATH/src/github.com/common# to add the server's go project code to the docker container ADD. GOPATH/src/github.com/common# exposes port EXPOSE 300 runs the command ENTRYPOINT of docker [". / common"]
Package image
Docker build-t common. After reading the above content, do you have a better understanding of how Docker deploys the basic image of Go? if you want to learn more, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.