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.