golang go path和go mod的区别
go path 所有运行的go文件都要放在gopath文件下, 因为下载下来的包都在这里目录下可以引用
go path顾名思义,需要一个环境变量 GOPATH/src 存放项目源代码
$GOPATH/bin 存放项目可执行文件
go mod 他有一套引用机制 无论你的go文件在哪里 都可以引用包
go path方式
#编译镜像
FROM golang:latest as builder
MAINTAINER TigerwolfC@***.com.cn
WORKDIR /go/src
COPY . .
RUN go build -o myapp
#产物运行镜像
FROM alpine:latest
WORKDIR /root
COPY --from=builder /go/src/myapp .
EXPOSE 8088
CMD [“./myapp”]
go mod方式
FROM golang:latest as build
#ENV GOPROXY https://goproxy.io
ENV GO111MODULE on
WORKDIR /go/cache
ADD go.mod .
ADD go.sum .
RUN go mod download
WORKDIR /go/release
ADD . .
RUN GOOS=linux CGO_ENABLED=0 go build -ldflags="-s -w" -installsuffix cgo -o gin_demo main.go
FROM scratch as prod
COPY --from=build /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
COPY --from=build /go/release/gin_demo /
COPY --from=build /go/release/conf ./conf
CMD ["/gin_demo"]
有疑问加站长微信联系(非本文作者)