Use alpinelinux to build golang http started before being 15mb

1, about alpine environment yesterday studied the next golang http server.
Found at the time of the start being given:
No such file or directory

Found this error, the beginning also thought that alpine system lib library less,
Must use Docker's official golang image?
Later research to understand, in fact, because my host is centos.
I compiled the golang on centos and copied it to the alpine environment.
New wisdom cloud
1, use golang: alpine mirror 241 mb to compile, mapping a folder.
2, and then copy the compiled file out, put alpine on the mirror can be.

Such a 15.24 MB golang environment just fine.
Because it also installed a bash, you can enter the system view.

2, the operation process first build a golang build environment.
FROM RUN echo " https: //mirror.tuna.tsinghua.e … ot% 3B > / etc / apk / repositories RUN apk add –update curl bash && \ rm -rf / var / Cache / apk / *

Compiled Mirror:

Docker build -t demo / go-build: 1.0.

Start the mirror and map the / data / Go directory to the / data / go directory, where -rm indicates that the mirror is removed after exiting.

Docker run -it -v / data / go: / data / go –rm demo / go-build: 1.0 / bin / bash

Cd / data / go

Go build http.go

Where http.go file:
Package main import ("fmt" "net / http") func handler (w http.ResponseWriter, r * http.Request) {fmt.Fprintf (w, "Hi there, I love% s!", R.URL.Path [1:])} func main () {http.HandleFunc ("/", handler) http.ListenAndServe ("", nil)}

From golang official httpdemo.

3, alpine and go http will be packaged in alpine environment compiled http package and then do a mirror, copy to alpine system:

MAINTAINER demo <juest a demo>

RUN echo " https: //mirror.tuna.tsinghua.e … ot% 3B > / etc / apk / repositories

RUN apk add –update curl bash && \
Rm -rf / var / cache / apk / *

RUN mkdir -p / data / go
COPY http / data / go


ENTRYPOINT ["/ data / go / http"]

Package and start http.

Docker build -t demo / go-http: 1.0.
Docker run -d -p 8080: 8080 –name go-http demo / go-http: 1.0

Direct access curl localhost: 8080 can be a.

4, summary

This is a very good implementation, no wonder golang known as the language of cloud computing design it. Directly in the alpine 5mb system running on the installation of a bash, a total of only 15 mb, ye do version upgrade, version backup will do.
Powerful my brother, golang is really like it.
Ready to design the background of the system design with golang rewrite it.
In fact, Java can do golang can do it.
Java hit a jre are more than 100 mb. Look at people golang only a few mb.
Everything is homogeneous. Golang is really the language of cloud computing it
See details:

Heads up! This alert needs your attention, but it's not super important.