Skip to content

Instantly share code, notes, and snippets.

@donvito
Last active November 2, 2019 05:35
Show Gist options
  • Save donvito/4b6d9ac37103717714f946b90bd26f5b to your computer and use it in GitHub Desktop.
Save donvito/4b6d9ac37103717714f946b90bd26f5b to your computer and use it in GitHub Desktop.
Dockerfile to build a docker image with a main.go gist
FROM golang:1.13.4 AS builder
ARG GIST_RAW_URL
RUN mkdir /app
RUN curl $GIST_RAW_URL --output /app/main.go
WORKDIR /app
RUN CGO_ENABLED=0 GOOS=linux go build -o main ./...
FROM alpine:latest AS production
COPY --from=builder /app .
CMD ["./main"]
package main
import "fmt"
func main() {
fmt.Println("Hello universe! test running the code from a gist!")
person := Person{name:"Melvin"}
person.sayName()
}
package main
import "fmt"
type Person struct {
name string
}
func (person *Person) sayName() {
fmt.Printf("Name is %s", person.name)
}
@donvito
Copy link
Author

donvito commented Sep 26, 2019

To use:

  1. docker build -f Dockerfile -t go-multi-stage --build-arg GIST_RAW_URL=https://gist.githubusercontent.com/donvito/4b6d9ac37103717714f946b90bd26f5b/raw/923246357e1f3aa0e97d9158566a2021a7caafcd/main.go .

  2. docker run go-multi-stage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment