build image from latest sources
docker build .
run sources (from docker container, will be deleted after exits)
# --rm deletes container after it exits
# -t for tty
# -i for interactive
docker run --rm -ti maxfunke/go-training
| # Multistage build | |
| FROM golang:alpine as build | |
| ## stage1: build app, make use of /go/src | |
| RUN mkdir /go/src/app | |
| WORKDIR /go/src/app | |
| ## copy sources to build-image | |
| ADD ./src/main.go /go/src/app | |
| RUN go build -o /bin/app | |
| ## stage2: copy built bin to plain-image | |
| FROM scratch | |
| COPY --from=build /bin/app /bin/app | |
| ENTRYPOINT ["/bin/app"] |