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 just
FROM golang:onbuild
EXPOSE 8080
based on this article Deploying Go servers with Docker
I use this code git-go-websiteskeleton as the source for building the docker. the full error is here.
import "git-go-websiteskeleton/app/common": import path does not begin with hostname package git-go-websiteskeleton/app/common: unrecognized import path "git-go-websiteskeleton/app/common" import "git-go-websiteskeleton/app/home": import path does not begin with hostname package git-go-websiteskeleton/app/home: unrecognized import path "git-go-websiteskeleton/app/home" import "git-go-websiteskeleton/app/user": import path does not begin with hostname package git-go-websiteskeleton/app/user: unrecognized import path "git-go-websiteskeleton/app/user"
Thank you for a help.
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.
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"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With