This is a creation in Article, where the information may have evolved or changed.
1,alpine Linux is very small
First Alpine is very small, installed on the bash after the 5MB.
Golang don't need any other dependencies to see if they can run on Alpine.
Build a Golang environment, rather than putting the golang environment on the Alpine.
2, first build Golang environment in CentOS
Https://golang.org/doc/install
Download and unzip:
tar -C /usr/local -xzf go1.7.4PATH=$PATH:/usr/local/go/binGOPATH=/data/go
Suppose Gopath is below the/data/go directory.
Writing Http.go
package mainimport ( "fmt" "net/http")func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf"Hi there, I love %s!", r.URL.Path[1:])}func main() { http.HandleFunc("/", handler) http.ListenAndServe("0.0.0.0:8080", nil)}
Very simple.
Go Build Http.go
./http
3, write the Docker build
VI Dockerfile
FROM docker.io/alpine:latestMAINTAINER demo <juest a demo>RUN--update curl bash && \ rm -rf /var/cache/apk/*WORKDIR /dataONBUILDCOPY http /dataEXPOSE8080ENTRYPOINT ["/data/http"]
Created a minimal docker mirroring environment. Then set the source to Tsinghua. and the curl and bash tools are installed.
4, start
demo/go-http 1.0 b180c236066d 11seconds ago 9.555 MB
There are only 10mb of containers, very small.
But the reality is brutal. Because the Alpine is too streamlined. Cause Golang not to get up.
See a kernel Linux is not bootable Golang.
The final dockerfile:
FROM docker.io/golang:latestMAINTAINER demo <juest a demo>RUN"https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main" > /etc/apk/repositoriesRUN--update curl bash && \ rm -rf /var/cache/apk/*WORKDIR /dataONBUILDCOPY http /dataEXPOSE8080ENTRYPOINT ["/data/http"]
Or use the Docker's official Golang environment in order to start.
Otherwise the error
fileordirectory
The executable file could not be found. The container cannot be started.
5, summary
The text of this text connection is: http://blog.csdn.net/freewebsys/article/details/53615757 not allowed to reprint without the Bo master.
Bo main address is: Http://blog.csdn.net/freewebsys
Eventually the Golang was launched in an official environment.
Didn't figure out what the Golang really needed.
Final size is 679.6 MB
I thought 10mb would solve the problem. It seems to be a good exploration.
Other environments can also be studied.