aldikhan13

EXAMPLE GO DOCKERFILE

Apr 1st, 2021 (edited)
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. # ======================
  2. # GO FIRST STAGE
  3. # ======================
  4.  
  5. FROM golang:latest as download
  6. WORKDIR /usr/src/app
  7. USER ${USER}
  8. COPY go.mod go.sum ./
  9. COPY . ./
  10. ENV GO111MODULE="on" \
  11. GOARCH="amd64" \
  12. GOCACHE="/${HOME}/.cache/go-build" \
  13. GOENV="/${HOME}/.config/go/env" \
  14. GOMODCACHE="/${HOME}/go/pkg/mod" \
  15. GOPATH="/${HOME}/go" \
  16. GOOS="linux" \
  17. GOTOOLDIR="/${HOME}/go/pkg/tool/linux_amd64" \
  18. GCCGO="gccgo" \
  19. CC="gcc" \
  20. CXX="g++" \
  21. CGO_ENABLED="0"
  22. RUN apt-get autoclean \
  23. && apt-get autoremove \
  24. && apt-get clean \
  25. apt-get remove
  26.  
  27. # ======================
  28. # GO SECOND STAGE
  29. # ======================
  30.  
  31. FROM download as utilities
  32. RUN apt-get update \
  33. && apt-get install -y \
  34. build-essential \
  35. wget \
  36. unzip \
  37. make \
  38. vim \
  39. git
  40.  
  41. # ======================
  42. # GO THIRD STAGE
  43. # ======================
  44.  
  45. FROM utilities as build
  46. WORKDIR /usr/src/app
  47. RUN go get -f -u -v -fix all \
  48. go build -o main
  49. COPY --from=utilities . /usr/src/app/
  50.  
  51. # ======================
  52. # GO FINAL STAGE
  53. # ======================
  54.  
  55. FROM alpine:latest
  56. COPY --from=build /usr/src/app .
  57. EXPOSE 3000
  58. CMD ["./main"]
Add Comment
Please, Sign In to add comment