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 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示