1

我有以下内容Dockerfile

FROM golang:1.9.2

ADD . /go/src/github.com/golang/example/outyet
ADD . /go/src/github.com/derekparker/delve/cmd/dlv

RUN go install github.com/golang/example/outyet
RUN go install github.com/derekparker/delve/cmd/dlv

RUN ["chmod", "+x", "/go/src/github.com/golang/example/outyet/bootstrap.sh"]
CMD ["/go/src/github.com/golang/example/outyet/bootstrap.sh"]

EXPOSE 8091
EXPOSE 5432

和以下bootstrap.sh

#!/bin/sh
go build -gcflags='-N -l' github.com/golang/example/outyet && 
dlv --listen=:5432 --headless=true --api-version=2 exec outyet;

使用以下行运行容器和映像后:

sudo docker build -t outyet .
sudo docker run -p 6060:8091 -p 5432:5432  --name test --rm outyet

我得到以下输出:

flag provided but not defined: -listen
Usage of dlv:
  -http string
        Listen address (default ":8091")
  -poll duration
        Poll period (default 1s)
  -version string
        Go version (default "1.4")

当我在我的 ubuntu 主机上本地运行 bootstrap.sh 时,一切正常。怎么了?

4

1 回答 1

3

我能够修复它,我Dockerfile现在看起来像这样:

FROM golang:1.9.2

ADD . /go/src/github.com/golang/example/outyet

RUN go install github.com/golang/example/outyet
RUN ["chmod", "+x", "/go/src/github.com/golang/example/outyet/bootstrap.sh"]
RUN ["chmod", "+x", "/go/bin/outyet"]

CMD ["/go/src/github.com/golang/example/outyet/bootstrap.sh"]

EXPOSE 8091
EXPOSE 5432

引导程序.sh:

#!/bin/sh
go get github.com/derekparker/delve/cmd/dlv;
go build -gcflags='-N -l' github.com/golang/example/outyet && 
dlv --listen=:5432 --headless=true --api-version=2 exec outyet

并按如下方式运行:

sudo docker build -t outyet .
sudo docker run --security-opt=seccomp:unconfined --net=host  --name test --rm outyet
于 2017-12-14T12:22:38.813 回答