Dockerfile golang构建

问题描述 投票:0回答:1

我正在构建Go应用程序。我收到如下错误

# cd .; git clone https://github.com/julienschmidt/httprouter /go/src/github.com/julienschmidt/httprouter Cloning into
'/go/src/github.com/julienschmidt/httprouter'... fatal: unable to
access 'https://github.com/julienschmidt/httprouter/': Could not
resolve host: github.com package github.com/julienschmidt/httprouter:
exit status 128
The command '/bin/sh -c go get ./' returned a non-zero code: 1

docker文件。

# install dependencies first
RUN go get ./

RUN go build

CMD if [ ${APP_ENV} = production ]; \
    then \
    main; \
    else \
    go get github.com/pilu/fresh && \
    fresh; \
    fi

EXPOSE 8080

构建命令:

docker image build -t test:1.0 .

感谢。有什么帮助吗?

docker go
1个回答
4
投票
  1. 检查DNS服务器
  2. 检查互联网连接
  3. 您可以在文件夹中使用脚本克隆存储库,然后将文件夹复制到Docker并构建项目。实施例

    FROM golang:1.9 as builder  
    RUN mkdir -p /go/src/folder   
    WORKDIR /go/src/folder    
    COPY src/ .  
    RUN go get -d  
    RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o app .    
    
    
    
    FROM alpine:latest  
    WORKDIR /
    COPY --from=builder /go/src/folder/app .  
    CMD ["/app"]
    
© www.soinside.com 2019 - 2024. All rights reserved.