Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting "cannot find package" trying to build my application in a docker container

Tags:

docker

go

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.

like image 240
Richard Avatar asked Apr 19 '14 14:04

Richard


1 Answers

I solved something similar to this by using

go get ./...

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

like image 95
Luis Avatar answered Sep 30 '22 02:09

Luis