Docker (9): Built with Alpinelinux Golang http started, only 15MB

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

The text of this text connection is: http://blog.csdn.net/freewebsys/article/details/53635529 not allowed to reprint without the Bo master.
Bo main address is: Http://blog.csdn.net/freewebsys

1, about alpine environment

http://blog.csdn.net/freewebsys/article/details/53615757
The HTTP server for the next Golang was studied yesterday.
Found an error when booting:

fileordirectory

Found this error, began to think is Alpine system Lib library less,
You must use the official Docker Golang image.
Later the study understood that it was because my host was CentOS.
I compiled the Golang on CentOS and then copied it to the alpine environment.
Solution.
1, compile with golang:alpine image 241 MB, map a folder.
2, then copy the compiled files and put them on the Alpine mirror.

Such a 15.24 MB Golang environment is good.
Because a bash is also installed, you can enter the system to view it.

2, Operation Process

First, build a Golang build environment.

FROM       docker."https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main">--&&\    -rf /var/cache/apk/*

To compile the image:

-t demo/go-build:1.0.

Start mirroring and map the/data/go directory to the/data/go directory, where – RM indicates that mirroring is removed after exiting.

-it-v /data/go:/data--rm demo/go-build:1.0 /bin/bash#cd /data/go#go build http.go

where Http.go file:

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)}

Excerpt from the official Httpdemo of Golang.

3, Package alpine and go http

The HTTP packets compiled in the alpine environment are then mirrored and copied to the Alpine system:

FROM       docker.io/alpine: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/*RUN mkdir -p /data/goCOPY http /data/goEXPOSE8080ENTRYPOINT ["/data/go/http"]

Pack and start the HTTP.

-t demo/go-http:1.0.-d-p8080:8080--name go-http demo/go-http:1.0

Direct access to Curl localhost:8080.

4, summary

The text of this text connection is: http://blog.csdn.net/freewebsys/article/details/53635529 not allowed to reprint without the Bo master.
Bo main address is: Http://blog.csdn.net/freewebsys

This is a very good implementation, no wonder Golang claims to be the language of cloud computing design. Run directly on the Alpine 5MB system, in the installation of a bash, a total of only a total of MB, I do version upgrade, version backup is OK.
My brother, Golang really liked it.
Prepare the backend system design with Golang rewrite it.
In fact, Java can do Golang can do it.
Java has been playing the JRE above the last. Look at others Golang only a few megabytes.
everything is all up. Golang really is the language of cloud computing.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.