Error 'import path does not begin with hostname' when building docker with local package

后端 未结 2 2042
感动是毒
感动是毒 2021-01-08 00:08

I\'m trying to build a docker with a local package but get the error \'import path does not begin with hostname\'. If my understanding is correct, my Dockerfile should be ju

相关标签:
2条回答
  • 2021-01-08 00:42

    Try :

    FROM golang:latest
    RUN mkdir /go/src/app
    WORKDIR /go/src/app
    ADD ./HelloWorld.go ./
    RUN go get
    RUN go build -o main .
    CMD ["/go/src/app/main"]
    
    0 讨论(0)
  • 2021-01-08 00:56

    The application is built inside the docker container and you need to have your dependencies available when building.

    golang:onbuild gives compact Dockerfiles for simple cases but it will not fetch your dependencies.

    You can write your own Dockerfile with the steps needed to build your application. Depending on how your project looks you could use something like this:

    FROM golang:1.6
    ADD . /go/src/yourapplication
    RUN go get github.com/jadekler/git-go-websiteskeleton
    RUN go install yourapplication
    ENTRYPOINT /go/bin/yourapplication
    EXPOSE 8080
    

    This adds your source and your dependency into the container, builds your application, starts it, and exposes it under port 8080.

    0 讨论(0)
提交回复
热议问题