使用本地包构建 docker 时出现错误“导入路径不以主机名开头" [英] Error 'import path does not begin with hostname' when building docker with local package

查看:20
本文介绍了使用本地包构建 docker 时出现错误“导入路径不以主机名开头"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用本地包构建 docker,但收到错误导入路径不以主机名开头".如果我的理解是正确的,我的 Dockerfile 应该只是

来自 golang:onbuild曝光 8080

基于本文使用 Docker 部署 Go 服务器

我使用此代码 git-go-websiteskeleton 作为构建 docker 的源代码.完整的错误在这里.

<上一页>导入git-go-websiteskeleton/app/common":导入路径不以主机名开头包 git-go-websiteskeleton/app/common:无法识别的导入路径git-go-websiteskeleton/app/common"导入git-go-websiteskeleton/app/home":导入路径不以主机名开头包 git-go-websiteskeleton/app/home:无法识别的导入路径git-go-websiteskeleton/app/home"导入git-go-websiteskeleton/app/user":导入路径不以主机名开头包 git-go-websiteskeleton/app/user:无法识别的导入路径git-go-websiteskeleton/app/user"

感谢您的帮助.

解决方案

应用程序构建在 docker 容器中,构建时需要有可用的依赖项.

golang:onbuild 为简单的情况提供了紧凑的 Dockerfile,但它不会获取您的依赖项.

您可以编写自己的 Dockerfile,其中包含构建应用程序所需的步骤.根据您的项目的外观,您可以使用以下内容:

来自 golang:1.6添加 ./go/src/yourapplication运行去获取 github.com/jadekler/git-go-websiteskeletonRUN 去安装你的应用程序入口点/go/bin/yourapplication曝光 8080

这会将您的源代码和依赖项添加到容器中,构建您的应用程序,启动它,并在端口 8080 下公开它.

I'm trying to build a docker with a local package but get the error 'import path does not begin with hostname'. If my understanding is correct, my Dockerfile should be just

FROM golang:onbuild
EXPOSE 8080

based on this article Deploying Go servers with Docker

I use this code git-go-websiteskeleton as the source for building the docker. the full error is here.

import "git-go-websiteskeleton/app/common": import path does not begin with hostname
package git-go-websiteskeleton/app/common: unrecognized import path "git-go-websiteskeleton/app/common"
import "git-go-websiteskeleton/app/home": import path does not begin with hostname
package git-go-websiteskeleton/app/home: unrecognized import path "git-go-websiteskeleton/app/home"
import "git-go-websiteskeleton/app/user": import path does not begin with hostname
package git-go-websiteskeleton/app/user: unrecognized import path "git-go-websiteskeleton/app/user"

Thank you for a help.

解决方案

The application is built inside the docker container and you need to have your dependencies available when building.

golang:onbuild gives compact Dockerfiles for simple cases but it will not fetch your dependencies.

You can write your own Dockerfile with the steps needed to build your application. Depending on how your project looks you could use something like this:

FROM golang:1.6
ADD . /go/src/yourapplication
RUN go get github.com/jadekler/git-go-websiteskeleton
RUN go install yourapplication
ENTRYPOINT /go/bin/yourapplication
EXPOSE 8080

This adds your source and your dependency into the container, builds your application, starts it, and exposes it under port 8080.

这篇关于使用本地包构建 docker 时出现错误“导入路径不以主机名开头"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆