GOPATH/src/<import-path>
你可以用你的方式来管理它们
go get
工具。
考虑
vendoring
dep
或
modules
您还可以改进您的创建方式
Docker
形象。
GO
工具链。代码被复制到该容器中,容器编译并承载代码。生产只需要晚一点。
更好的选择是使用2个容器:
-
Go编译工具
-
仅承载二进制文件的轻量级容器
# Debian image with the latest version of Go installed
# and a workspace (GOPATH) configured at /go.
FROM golang:1.11 as builder
WORKDIR /go/src/github.com/space/project/
# Copy the local package files to the container's workspace.
ADD . /go/src/github.com/space/project/
# Build the service inside the container.
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
FROM centurylink/ca-certs
EXPOSE 8080
# Copy app
COPY --from=builder /go/src/github.com/space/project/app /
ENTRYPOINT ["/app"]