Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 763
panchapol Avatar asked Apr 21 '15 14:04

panchapol


2 Answers

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.

like image 123
Niemi Avatar answered Nov 03 '22 21:11

Niemi


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"]
like image 35
the4thamigo_uk Avatar answered Nov 03 '22 22:11

the4thamigo_uk