dongweihuan8610 2017-03-06 06:56
浏览 56

运行Go image时无法识别的导入路径“ main / testPackage”

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 MapReduce实现倒排索引失败
    • ¥15 luckysheet
    • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
    • ¥15 找一位技术过硬的游戏pj程序员
    • ¥15 matlab生成电测深三层曲线模型代码
    • ¥50 随机森林与房贷信用风险模型
    • ¥50 buildozer打包kivy app失败
    • ¥30 在vs2022里运行python代码
    • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
    • ¥15 求解 yolo算法问题