Building Docker Images for Static Go Binaries

FROM google/debian:wheezy
MAINTAINER Kelsey Hightower <kelsey.hightower@gmail.com>
RUN apt-get update -y && apt-get install —no-install-recommends -y -q curl build-essential ca-certificates git mercurial
# Install Go
# Save the SHA1 checksum from http://golang.org/dl
RUN echo '9f9dfcbcb4fa126b2b66c0830dc733215f2f056e go1.3.src.tar.gz' > go1.3.src.tar.gz.sha1
RUN curl -O -s https://storage.googleapis.com/golang/go1.3.src.tar.gz
RUN sha1sum —check go1.3.src.tar.gz.sha1
RUN tar -xzf go1.3.src.tar.gz -C /usr/local
ENV PATH /usr/local/go/bin:$PATH
ENV GOPATH /gopath
RUN cd /usr/local/go/src && ./make.bash —no-clean 2>&1
WORKDIR /gopath/src/github.com/kelseyhightower/contributors# Build the Contributors application
RUN mkdir -p /gopath/src/github.com/kelseyhightower/contributors
ADD . /gopath/src/github.com/kelseyhightower/contributors
RUN CGO_ENABLED=0 GOOS=linux go build -a -tags netgo -ldflags '-w' .
RUN cp contributors /contributors
ENV PORT 80
EXPOSE 80
ENTRYPOINT ["/contributors"]
FROM google/debian:wheezy
MAINTAINER Kelsey Hightower <kelsey.hightower@gmail.com>
ADD contributors contributors
ENV PORT 80
EXPOSE 80
ENTRYPOINT ["/contributors"]
CGO_ENABLED=0 GOOS=linux go build -a -tags netgo -ldflags '-w' .
docker build -t kelseyhightower/contributors .
FROM scratch
MAINTAINER Kelsey Hightower <kelsey.hightower@gmail.com>
ADD contributors contributors
ENV PORT 80
EXPOSE 80
ENTRYPOINT ["/contributors"]
x509: failed to load system roots and no roots provided
func init() {
pool = x509.NewCertPool()
pool.AppendCertsFromPEM(pemCerts)
client = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{RootCAs: pool},
},
}
}
docker run -d -P kelseyhightower/contributors

--

--

--

Sysadmin who can code.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kelsey Hightower

Kelsey Hightower

Sysadmin who can code.

More from Medium

Understanding SPIRE Kubernetes Workload Registrar

Deploy IPI Bare Metal OpenShift in a Disconnected Environment

Zero Touch Provisioning IOT or Other Devices on cloud

Deployment, DevOps, and Docker