Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go get golang docker图像导致分割错误_Docker_Go - Fatal编程技术网

Go get golang docker图像导致分割错误

Go get golang docker图像导致分割错误,docker,go,Docker,Go,我正在尝试在docker映像中运行Go web应用程序。通过运行go get安装依赖项时,我遇到了分段错误。安装依赖项并在本地运行“go build”时,我能够正确编译 我曾尝试使用glide和dep来提供依赖项,但我不确定这里是否存在依赖项管理问题。我也不确定为什么在使用go get-v中的-v标志时,最后安装的依赖项是github.com/user/hftl/app,这是我将所有.go文件复制到容器中的目录 我在用Docker做Mac 运行docker build的输出。/ Sending

我正在尝试在docker映像中运行Go web应用程序。通过运行go get安装依赖项时,我遇到了分段错误。安装依赖项并在本地运行“go build”时,我能够正确编译

我曾尝试使用glide和dep来提供依赖项,但我不确定这里是否存在依赖项管理问题。我也不确定为什么在使用
go get-v
中的
-v
标志时,最后安装的依赖项是
github.com/user/hftl/app
,这是我将所有
.go
文件复制到容器中的目录

我在用Docker做Mac

运行docker build的输出。/

Sending build context to Docker daemon  11.78MB
Step 1/9 : FROM golang:1.10
 ---> 1c1309ff8e0d
Step 2/9 : ARG app_env
 ---> Using cache
 ---> 4a9c7610a671
Step 3/9 : ENV APP_ENV $app_env
 ---> Using cache
 ---> 577846d489df
Step 4/9 : COPY ./app /go/src/github.com/user/hftl/app
 ---> 4a531e5ed4c1
Step 5/9 : WORKDIR /go/src/github.com/user/hftl/app
Removing intermediate container 5b21fc994dba
 ---> 878133804037
Step 6/9 : RUN go get -v
 ---> Running in a8ba8b45ffcc
github.com/gin-gonic/gin (download)
github.com/gin-contrib/sse (download)
github.com/golang/protobuf (download)
github.com/ugorji/go (download)
Fetching https://gopkg.in/go-playground/validator.v8?go-get=1
Parsing meta tags from https://gopkg.in/go-playground/validator.v8?go-get=1 (status code 200)
get "gopkg.in/go-playground/validator.v8": found meta tag get.metaImport{Prefix:"gopkg.in/go-playground/validator.v8", VCS:"git", RepoRoot:"https://gopkg.in/go-playground/validator.v8"} at https://gopkg.in/go-playground/validator.v8?go-get=1
gopkg.in/go-playground/validator.v8 (download)
Fetching https://gopkg.in/yaml.v2?go-get=1
Parsing meta tags from https://gopkg.in/yaml.v2?go-get=1 (status code 200)
get "gopkg.in/yaml.v2": found meta tag get.metaImport{Prefix:"gopkg.in/yaml.v2", VCS:"git", RepoRoot:"https://gopkg.in/yaml.v2"} at https://gopkg.in/yaml.v2?go-get=1
gopkg.in/yaml.v2 (download)
github.com/mattn/go-isatty (download)
github.com/kelseyhightower/envconfig (download)
github.com/lib/pq (download)
github.com/lib/pq/oid
github.com/gin-gonic/gin/json
github.com/gin-contrib/sse
github.com/golang/protobuf/proto
gopkg.in/go-playground/validator.v8
github.com/ugorji/go/codec
gopkg.in/yaml.v2
github.com/mattn/go-isatty
github.com/kelseyhightower/envconfig
github.com/lib/pq
github.com/gin-gonic/gin/render
github.com/gin-gonic/gin/binding
github.com/gin-gonic/gin
github.com/user/hftl/app
go tool link: signal: segmentation fault
The command '/bin/sh -c go get -v' returned a non-zero code: 1
我的Dockerfile:

FROM golang:1.10

ARG app_env

# assign app_env variable from build -> APP_ENV in container shell
# can either be dev or production: set in docker-compose.yml under 'web'
ENV APP_ENV $app_env

# copy app directory to container
COPY ./app /go/src/github.com/user/hftl/app

# all container commands run from this path
WORKDIR /go/src/github.com/user/hftl/app

# install go deps and build binary
RUN go get -v
RUN go build

# start the server
# hot-reload via pilu/fresh on save of a Go file
CMD if [ ${APP_ENV} = production ]; then \
        app; \
        else \
        go get github.com/pilu/fresh && \
        fresh; \
        fi

EXPOSE 8080
[编辑1]:


我将Dockerfile顶部的
从golang:1.10
更改为
从golang:1.9.4
,似乎已经解决了问题,因此这一定是官方go 1.10图像的问题。如果有人能澄清为什么
go-tool-link
会在1.10而不是1.9.4上产生分段错误,那就太好了。

当您有文本输出时,请更正,抱歉-在你本地机器上的S.O.@JustinYeh上的第一篇帖子是
/app
文件夹,也位于
$GOPATH/src/github.com/user/hftl/
?@mkopriva
/app
的完整路径是
~/go/src/github.com/jyyeh77/hftl/
,但我认为只要通过
复制Dockerfile中的./app/go/src/github.com/user/hftl
,并设置工作目录。或者这有关系吗?@JustinYeh我想,我不确定,如果你在
/app
下有子包,比如说
/app/foo
,并且你的应用程序正在导入它们,这会有关系。比如说在
/app/main.go
中,如果你有一个类似于
“github.com/jyyeh77/hftl/app/foo”
的导入,但在docker上它位于
“github.com/user/hftl/app/foo”下,那么我相信这可能会导致一问题,但我不确定是否会导致链接器故障。既然您能够通过将版本更改为1.9来解决这个问题,这意味着您要么没有导入的子包,要么实际上根本没有问题?