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.
New Wisdom Cloud www.enncloud.cn
2, first build Golang environment in CentOS
Https://golang.org/doc/install
Download and unzip:
Tar-c/usr/local-xzf go1. 7.4.linux-amd64.tar.gz Setting Environment variables: Export path=$PATH:/usr/local/go/binexportgopath=/data/go
Suppose Gopath is below the/data/go directory.
Writing Http.go
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 ("0.0.0.0:8080", Nil)}
Very simple.
Go Build Http.go
./http
3, write the Docker build
VI Dockerfile
From Docker.io/alpine:latest
Maintainer Demo <juest a demo>
RUN apk add --update Curl bash && \ rm-rf/var/cache/apk/*
Workdir/Data
Onbuild COPY http/data
EXPOSE 8080
entrypoint ["/data/http"]
Created a minimal docker mirroring environment. Then set the source to Tsinghua. and the curl and bash tools are installed.
4, start
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:latest
Maintainer Demo <juest a demo>
RUN echo "Https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main" >/etc/apk/repositories
RUN apk add --update Curl bash && \
rm-rf/var/cache/apk/*
Workdir/Data
Onbuild COPY http/data
EXPOSE 8080
entrypoint ["/data/http"]
Or use the Docker's official Golang environment in order to start.
Otherwise the error
No such file or directory
The executable file could not be found. The container cannot be started.
5, summary
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.
Facets | Build Golang http with Alpinelinux to see how small it can be.