Skip to content

Instantly share code, notes, and snippets.

@knjname
Last active March 12, 2018 04:10
Show Gist options
  • Select an option

  • Save knjname/8d87504b8ecdc57e73cd95f892581b6d to your computer and use it in GitHub Desktop.

Select an option

Save knjname/8d87504b8ecdc57e73cd95f892581b6d to your computer and use it in GitHub Desktop.
Building go docker image `FROM scratch`

Golang Docker image building sample

$ docker-compose build buildgo
$ docker run gohello
version: "3"
services:
buildgo:
build: ./
image: gohello:1.0
FROM golang AS builder
WORKDIR /
ADD ./helloworld.go /helloworld.go
RUN ["go", "build", "/helloworld.go"]
FROM scratch
COPY --from=builder /helloworld /helloworld
CMD ["/helloworld"]
package main
import "fmt"
func main() {
fmt.Println("Hello world")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment