7

Here is my Dockerfile.

FROM ubuntu
MAINTAINER me <[email protected]>
RUN apt-get update && apt-get install -y \
build-essential \
curl \
git \
make
# Get and compile go
RUN curl -s https://go.googlecode.com/files/go1.2.1.src.tar.gz | tar -v -C /usr/local -xz
RUN cd /usr/local/go/src && ./make.bash --no-clean 2>&1
ENV PATH /usr/local/go/bin:/go/bin:$PATH
ENV GOPATH /go
RUN go get github.com/gorilla/feeds
WORKDIR /go 
CMD go version && go install feed && feed

It builds just fine:

sudo docker build -t ubuntu-go .

but when I run it I get a package error:

sudo docker run -v /home/rbucker/go:/go --name go ubuntu-go

The error looks like:

src/feed/feed.go:7:2: cannot find package "github.com/gorilla/feeds" in any of: /usr/local/go/src/pkg/github.com/gorilla/feeds (from $GOROOT) /go/src/github.com/gorilla/feeds (from $GOPATH)

It's odd because "go install" is not installing the dependencies and while the previous "go get github.com/gorilla/feeds" completes without errors. So presumably I have a path or environment problem but all of the examples look just like this one.

PS: my code is located in /go/src/feed (feed.go)

package main

import (
    "net/http"
    "time"

    "github.com/gorilla/feeds"
)

. . .

UPDATE: when I performed the "go get" manually and then launched the "run" it seemed to work. So it appears that the "RUN go get" is storing my file in the ether instead of my host's volume.

sudo docker run -v /home/rbucker/go:/go --name go ubuntu-go /bin/bash

then

sudo docker run -v /home/rbucker/go:/go --name go ubuntu-go

(the files were located in my ~/go/src/githum.com and ~/go/pkg folders.)

UPDATE: It occurs to me that during the BUILD step the /go volume has not been attached to the docker image. So it's essentially assigned to nil. But then during the run the "get install" should have retrieved it's deps.

FINALLY: this works but is clearly not the preferred method:

CMD go get github.com/gorilla/feeds && go version && go install feed && feed

notice that I performed the "go get" in the CMD rather than a RUN.

4
  • 1
    go get automatically recurses dependencies, so rather than explicitly fetching gorilla you should just run go get on your own package and it should fetch/install all the dependencies in the right places. This should simplify things if you ever add more dependencies at least. Commented Apr 19, 2014 at 14:26
  • my package is local for the time being and so that won't work. Also, "go install" is supposed to recurse too, but it does not. "go get" is documented as an appropriate way to install the packages. It's also the preferred way to prevent HEAD bugs from dependencies from creeping in. Commented Apr 19, 2014 at 14:32
  • 1
    I assume you've gotten this working but leaving it for anyone else that encounters this issue, there's now a base image for golang apps on Docker which seems more straightforward Commented Oct 15, 2014 at 16:29
  • @Richard Please read Can I answer my own question? Commented Jun 17, 2015 at 23:31

1 Answer 1

5

I solved something similar to this by using

go get ./...

Source: https://coderwall.com/p/arxtja/install-all-go-project-dependencies-in-one-command

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.