15

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.

panchapol
  • 493
  • 1
  • 5
  • 15
  • Did you follow the directions in the README? `git-go-websiteskeleton` isn't in your GOPATH. – JimB Apr 21 '15 at 14:22
  • @JimB if you mean in my dev machine, I can run the project just fine. Only having the problem when trying to build the docker. – panchapol Apr 21 '15 at 14:55
  • Then how are you adding git-go-websiteskeleton to the image? Show us everything you're doing so I don't have to guess. – JimB Apr 21 '15 at 15:12
  • Thank you @JimB. My question may not clear enough. This is what I do. I clone the project to my src folder and run main.go which works okay. I can browse to localhost:8080 on my machine. Then I create a Dockerfile which has only "FROM golang:onbuild EXPOSE 8080" inside. Then I run the command "docker build -t git-go-websitesskeleton ." and then I got the errors. I'm very new to docker but I assume that the I need to add more instructions into the Dockerfile. I just don't quite sure because the [link](https://blog.golang.org/docker) says I could only add this ""FROM golang:onbuild EXPOSE 8080". – panchapol Apr 21 '15 at 16:46
  • You need to understand what the onbuild dockerfile is doing too. You don't need it, and It's probably better to just stop using that until you have a better grasp of what's going on. – JimB Apr 21 '15 at 16:51
  • @panchapol `onbuild` version of golang image is meant for really standard container run (meaning you don't import odd packages other than from the standards and common vcs). I recommend going for a conventional Dockerfile and trace the local steps and put them in the file. – Pandemonium Apr 09 '16 at 16:36
  • GOROOT is set incorrectly, see http://stackoverflow.com/a/20459819/149482 for more. – Matt Joiner Jul 14 '16 at 04:07

2 Answers2

2

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.

Niemi
  • 525
  • 2
  • 8
  • 13
1

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"]
the4thamigo_uk
  • 835
  • 4
  • 8