我正在尝试测试docker并进行项目。这是我的dockerfile
FROM golang
ARG app_env
ENV APP_ENV $app_env
COPY ./ /go/src/github.com/user/myProject/app
WORKDIR /go/src/github.com/user/myProject/app
RUN go get ./
RUN go build
CMD if [ ${APP_ENV} = production ]; \
then \
app; \
else \
go get github.com/pilu/fresh && \
fresh; \
fi
EXPOSE 8080
运行正常。然后我在go程序中添加了“testpack”包。
package main
import(
"fmt"
"time"
"testpack"
)
var now = time.Now()
var election = time.Date(2016, time.November, 8, 0, 0, 0, 0, time.UTC)
func main() {
//get duration between election date and now
tillElection := election.Sub(now)
//get duration in nanoseconds
toNanoseconds := tillElection.Nanoseconds()
//calculate hours from toNanoseconds
hours := toNanoseconds/3600000000000
remainder := toNanoseconds%3600000000000
//derive minutes from remainder of hours
minutes := remainder/60000000000
remainder = remainder%60000000000
//derive seconds from remainder of minutes
seconds := remainder/1000000000
//calculate days and get hours left from remainder
days := hours/24
hoursLeft := hours%24
fmt.Printf("\nHow long until the 2016 U.S. Presidential election?\n\n%v Days %v Hours %v Minutes %v Seconds\n\n", days, hoursLeft, minutes, seconds)
}
现在我跑=> docker build ./
我收到一个错误
程序包testpack:无法识别的导入路径“testpack”(导入路径不是以主机名开头)
我尝试了这个Error 'import path does not begin with hostname' when building docker with local package,但无法解决
任何帮助表示赞赏。
最佳答案
显然,它正在尝试从Internet加载它,因为它在您的GOPATH中找不到“testpack”。
您没有向我们显示您的GOPATH设置,也没有向您显示“testpack”的复制位置,因此,除了说“它丢失了”外,我只能告诉您。
阅读https://golang.org/cmd/go/#hdr-Relative_import_paths
尝试之一
import "./testpack"
import "github.com/user/myProject/app/testpack"