在使用本地程序包构建docker时错误'import path not not with hostname' [英] Error 'import path does not begin with hostname' when building docker with local package
问题描述
我试图用本地软件包构建一个docker,但得到错误导入路径不以hostname开头。如果我的理解是正确的,我的Dockerfile应该只是
FROM golang:onbuild
EXPOSE 8080
根据这篇文章部署Go服务器Docker
我使用这段代码 git-go-网站框架作为构建码头工具的来源。
导入git-go-websiteskeleton / app / common:导入路径不以主机名$ b开头$ b包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:import path does不以主机名开头
包git-go-websiteskeleton / app / user:无法识别的导入路径git-go-websiteskeleton / app / user
感谢您的帮助。
应用程序内置于docker容器中,您需要拥有
golang:onbuild
为简单案例提供了紧凑的Docker文件,但它不会获取您的依赖关系。
你可以使用构建应用程序所需的步骤编写自己的Dockerfile。根据你项目的外观,你可以使用这样的东西:
FROM golang:1.6
ADD。 / go / src / yourapplication
RUN go get github.com/jadekler/git-go-websiteskeleton
RUN安装您的应用程序
ENTRYPOINT / go / bin / yourapplication
EXPOSE 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时错误'import path not not with hostname'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!