-
-
Save PurpleBooth/ec81bad0a7b56ac767e0da09840f835a to your computer and use it in GitHub Desktop.
| FROM golang:1.9 | |
| WORKDIR /go/src/github.com/purplebooth/example | |
| COPY . . | |
| RUN go build -ldflags "-linkmode external -extldflags -static" -a main.go | |
| FROM scratch | |
| COPY --from=0 /go/src/github.com/purplebooth/example/main /main | |
| CMD ["/main"] |
Just stole this nice little dockerfile for a pet-project. Thanks for putting it out.
Btw: you do not need the first RUN to create the directory. WORKDIR will do that for you if it does not exist. :)
💯 this is really useful to know (especially when first messing with docker)
Really useful!
This is exactly what I needed. Thank you!
@ChristianKniep wrote:
Just stole this nice little dockerfile for a pet-project. Thanks for putting it out.
Btw: you do not need the firstRUNto create the directory.WORKDIRwill do that for you if it does not exist. :)
Ooh! Didn't know that! Updated 👍
Got this error when trying to run the container. Any idea? docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"./main\": permission denied": unknown.
Does main exist? The example copies to /main from the build container rather than ./main
Here's another similar example
I think I understand
-ldflags, it seems like it's used to make use of gnuldwhich can use the-staticflag to build a static library, but I don't understand why-ais needed (other examples use it as well).According to the docs it "force(s) rebuilding of packages that are already up-to-date.".
Is it because some built packages aren't built in a way that works when linking statically?