duancai7568 2018-03-11 21:59
浏览 66

去上golang docker图像导致分割错误

I'm trying to run a Go web app in a docker image. When installing dependencies via RUN go get, I get a segmentation fault. When installing dependencies and running go build locally, I'm able to compile correctly.

I have tried using glide and dep to vendor my dependencies, but I am not sure if dependency management is the issue here. I am also unsure why when using the -v flag in go get -v, the last dependency being installed is github.com/user/hftl/app, which is the directory that I'm copying all my .go files to in the container.

I'm using Docker For Mac.

Output of running 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

My 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

[EDIT 1]:

I changed the FROM golang:1.10 to FROM golang:1.9.4 at the top of my Dockerfile and it seems to have resolved the issue, so it must be a problem with the official go 1.10 image. If anyone could clarify why go tool link would produce a segmentation fault on 1.10, but not 1.9.4, that would be wonderful.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
    • ¥20 matlab yalmip kkt 双层优化问题
    • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体