用于golang应用程序的Docker

时间:2018-06-05 19:53:40

标签: docker go

我想要为它构建docker图像的golang应用程序 名为cloud-native-go的应用程序文件夹和dockerfile位于根项目下 知道这里有什么问题吗?

FROM golang:alpine3.7
WORKDIR /go/src/app
COPY . .
RUN apk add --no-cache git
RUN go-wrapper download   # "go get -d -v ./..."
RUN go-wrapper install    # "go install -v ./..."

#final stage
FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=builder /go/bin/app /app
ENTRYPOINT ./app
LABEL Name=cloud-native-go Version=0.0.1
EXPOSE 3000

错误是:

Step 5/12 : RUN go-wrapper download   # "go get -d -v ./..."
 ---> Running in 70c2e00f332d
/bin/sh: go-wrapper: not found

我用

构建它

docker build -t cloud-native-go:1.0.0 .

2 个答案:

答案 0 :(得分:2)

go-wrapper已被弃用,并使用go版本10及更高版本从图像中删除。见here

如果使用go v1.9表现良好,可以使用下面的图片:golang:1.9.6-alpine3.7

所以你的Dockerfile将是:

FROM golang:1.9.6-alpine3.7
WORKDIR /go/src/app
COPY . .
RUN apk add --no-cache git
RUN go-wrapper download   # "go get -d -v ./..."
RUN go-wrapper install    # "go install -v ./..."

#final stage
FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=builder /go/bin/app /app
ENTRYPOINT ./app
LABEL Name=cloud-native-go Version=0.0.1
EXPOSE 3000

答案 1 :(得分:0)

FROM golang:alpine

# important!
ENV GO111MODULE=on
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
ENV GOFLAGS=-mod=vendor
ENV APP_USER app
ENV APP_HOME /go/src/microservices

RUN mkdir /nameApp
ADD . /nameApp
WORKDIR /nameApp

//compile your project
RUN go mod vendor
RUN go build

//open the port 8000
EXPOSE 8000
CMD [ "/nameApp/nameApp" ]