dorbmd1177
dorbmd1177
采纳率100%
2018-10-15 14:11

Docker容器失败:“退出代码1”

已采纳

我试图在Docker容器中运行我的Go应用程序,但是它失败了,并给出了错误的退出代码1。该应用程序在我的本地机器上运行良好,但在Docker中不工作。

下面是我的Dockerfile:

FROM golang:1.8 as goimage

RUN go get -u github.com/golang/dep/cmd/dep

COPY . src/github.com/aditmayapada/tryout
WORKDIR src/github.com/aditmayapada/tryout


ENV PORT 9090

RUN dep ensure

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/main

FROM alpine:3.6 as baseimagealp
RUN apk add --no-cache bash
ENV WORK_DIR=/docker/bin
WORKDIR $WORK_DIR
# RUN mkdir src/github.com/aditmayapada/tryout/bin
# WORKDIR src/github.com/aditmayapada/tryout/bin
COPY --from=goimage /go/src/github.com/aditmayapada/tryout/bin ./
ENTRYPOINT /docker/bin/main
EXPOSE 9090

下面是我想在Docker中部署的应用程序库https://github.com/aditmayapada/tryout

我试着用docker事件来获取日志,但我只得到了这些 Logs,然后我尝试使用docker中的--logs,但是它没有显示任何东西。我是不是漏掉了什么?因为我的应用程序在我的本地机器上运行良好...谢谢。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongzhuo5185 dongzhuo5185 3年前

    I have briefly looked at your code and found that app could be finished in a case when connection.Ping() return err https://github.com/aditmayapada/tryout/blob/master/main.go#L44 I recommend adding some logging in this space to identify a point of exit. It seems something is wrong with connection to DB in docker.

    点赞 评论 复制链接分享

为你推荐