go容器build镜像
test="cd /go/src/grpc && apk add git && go get -d -v ./... && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o testserver" docker run --rm --net=host -v /opt/soft/test/sing:/go/src/grpc -v /opt/soft/mod:/go/pkg/mod golang:1.15.15-alpine3.14 sh -c "$test"
Dockerfile文件
FROM alpine:3.14 COPY testserver /usr/local/bin/ CMD ["/usr/local/bin/testserver"]
另外直接build方式Dockerfile文件
FROM golang:1.15.15-alpine3.14 as builder WORKDIR /go/src/grpcserver/ COPY . . RUN apk add git && go get -d -v ./... && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o testserver FROM alpine:3.14 COPY --from=builder /go/src/grpcserver/testserver /usr/local/bin/ EXPOSE 8080 CMD ["/usr/local/bin/testserver"]
请登录之后再进行评论