I am attempting to compile a golang project using docker, I am having trouble getting "go get" to compile the packages for me. the entire setup of the container can be seen below in my dockerfile:
FROM buildpack-deps:jessie-scm
# gcc for cgo
RUN apt-get update && apt-get install -y --no-install-recommends \
g++ \
gcc \
libc6-dev \
make \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
ENV GOLANG_VERSION 1.8
ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
ENV GOLANG_DOWNLOAD_SHA256 53ab94104ee3923e228a2cb2116e5e462ad3ebaeea06ff04463479d7f12d27ca
RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \
&& echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \
&& tar -C /usr/local -xzf golang.tar.gz \
&& rm golang.tar.gz
ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
ENV CGO_ENABLED 0
ENV GOOS linux
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
WORKDIR $GOPATH
RUN go get github.com/lib/pq
ENTRYPOINT ["go", "get", "."]
I build this container then use it to compile my go code using this command:
sudo docker run --rm -v /path/to/my/project:/usr/src/main -w /usr/src/main go:compiler
this finds the main.go in my project folder, reads through it.. but gives me this error when it encounters my import statements:
unrecognized import path "main/testPackage" (import path does not begin with hostname)
from what I have found in documentation, my understanding is the import path should be the folder in src, i.e. "main" in my case, followed by the directory structure.. what am I doing wrong? am I using go get incorrectly?