Go get on golang docker image 导致分段错误

Jus*_*Yeh 5 go docker

我正在尝试在 docker 映像中运行 Go Web 应用程序。通过RUN go get安装依赖项时,出现分段错误。当安装依赖项并在本地运行go build时,我能够正确编译。

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

我正在使用 Docker For 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
Run Code Online (Sandbox Code Playgroud)

我的 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
Run Code Online (Sandbox Code Playgroud)

[编辑1]:

我将 Dockerfile 顶部的 改为 ,似乎已经解决了问题,所以这肯定是官方 go 1.10 镜像的FROM golang:1.10问题。FROM golang:1.9.4如果有人能澄清为什么go tool link会在 1.10 上产生分段错误,但在 1.9.4 上不会,那就太好了。