去golang docker图像导致分段错误

时间:2018-03-11 21:59:41

标签: docker go

我正在尝试在泊坞窗图片中运行Go网络应用。通过 RUN go 安装依赖项时,我会遇到分段错误。在安装依赖项并在本地运行 go build 时,我能够正确编译。

我已尝试使用glide和dep来提供我的依赖项,但我不确定依赖项管理是否存在问题。我也不确定为什么在-v中使用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

我的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]:

我将Docker文件顶部的FROM golang:1.10更改为FROM golang:1.9.4,似乎已经解决了问题,所以它必须是官方版本1.10图像的问题。如果有人能够澄清为什么go tool link会在1.10而不是1.9.4上产生分段错误,那就太棒了。

0 个答案:

没有答案