构建Docker文件时无法获取依赖包

时间:2019-03-27 10:57:59

标签: docker go

我正在跟踪tutorial,了解有关Go中微服务的实现和部署。当我尝试基于Dockfile和go文件重建docker映像时,总是收到如下错误消息。 Dockerfile和go文件已附加,请问引起此错误的可能原因是什么?我已经尝试过Could not reserve host in docker提供的解决方案,但是--dns中没有docker build标志。

Dockerfile:

FROM golang:latest

COPY . /go/src/add
WORKDIR /go/src/add
RUN go get -d -v ./...
RUN go install -v ./...
ENTRYPOINT go run main.go
EXPOSE 3000

转到文件:

package main

import (
    "fmt"
    "github.com/shuza/kubernetes-go-grpc/pd"
    "golang.org/x/net/context"
    "google.golang.org/grpc"
    "google.golang.org/grpc/reflection"
    "log"
    "net"
)

type server struct{}

func main() {
    lis, err := net.Listen("tcp", ":3000")
    if err != nil {
        log.Fatalf("Failed to listen:  %v", err)
    }

    s := grpc.NewServer()
    pb.RegisterAddServiceServer(s, &server{})
    reflection.Register(s)
    if err := s.Serve(lis); err != nil {
        log.Fatalf("Failed to serve: %v", err)
    }
}

func (s *server) Compute(cxt context.Context, r *pb.AddRequest) (*pb.AddResponse, error) {
    result := &pb.AddResponse{}
    result.Result = r.A + r.B

    logMessage := fmt.Sprintf("A: %d   B: %d     sum: %d", r.A, r.B, result.Result)
    log.Println(logMessage)

    return result, nil
}

错误消息:

# cd .; git clone https://github.com/gorilla/mux /go/src/github.com/gorilla/mux
Cloning into '/go/src/github.com/gorilla/mux'...
fatal: unable to access 'https://github.com/gorilla/mux/': Could not resolve host: github.com
package github.com/gorilla/mux: exit status 128
# cd .; git clone https://github.com/shuza/kubernetes-go-grpc /go/src/github.com/shuza/kubernetes-go-grpc
Cloning into '/go/src/github.com/shuza/kubernetes-go-grpc'...
fatal: unable to access 'https://github.com/shuza/kubernetes-go-grpc/': Could not resolve host: github.com
package github.com/shuza/kubernetes-go-grpc/pd: exit status 128
package golang.org/x/net/context: unrecognized import path "golang.org/x/net/context" (https fetch: Get https://golang.org/x/net/context?go-get=1: dial tcp: i/o timeout)
package google.golang.org/grpc: unrecognized import path "google.golang.org/grpc" (https fetch: Get https://google.golang.org/grpc?go-get=1: dial tcp: i/o timeout)

0 个答案:

没有答案