donglao9606 2018-04-19 06:46
浏览 171
已采纳

如何使用main.go在文件夹内使用本地包构建docker镜像?

I'm trying docker build -t test_1 . , but have this err:

package docker_test/mult: unrecognized import path "docker_test/mult" (import path does not begin with hostname)

The command '/bin/sh -c go get -d -v ./...' returned a non-zero code: 1

My dockerfile (path /gowork/src/Dockerfile):

FROM golang:1.9.1
COPY ./docker_test/mult /go/src/app

WORKDIR go/src/app
COPY ./docker_test/main.go .

RUN go get -d -v ./...
RUN go install -v ./...

CMD ["app"]
ENTRYPOINT ["app", "-f=7", "-s=9"]

main.go (path: gowork/src/docker_test/main.go)

package main

import (
    "docker_test/mult"
    "fmt"
)

func main() {
    fmt.Println("From different pkg")
    mult.Multiple()
}

mult.go (path: gowork/src/docker_test/mult/mult.go)

package mult

import (
    "flag"
    "fmt"
)

func Multiple() {

    first := flag.Int("f", 0, "placeholder")
    second := flag.Int("s", 0, "placeholder")

    flag.Parse()

    out := (*first) * (*second)
    fmt.Println(out)

}
  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 实值特征权重向量和特征选择,多分类
      • ¥15 INVEST年产水量模块结果出处理
      • ¥15 Neo4j 不显示关系
      • ¥15 这段代码有什么bug
      • ¥15 pip默认安装位置修改不成功
      • ¥15 C++ inline、staitc、const三合一谁能讲通透
      • ¥15 关于pyqt5中QThread的问题
      • ¥20 STM32基于HAL库使用串口发送16进制数组
      • ¥15 OpenCV报错 You can enable it via 'OPENCV_IO_ENABLE_OPENEXR'
      • ¥15 AT89C51的程序问题