Flag provided but not defined

Rudziankoŭ picture Rudziankoŭ · Dec 13, 2017 · Viewed 9.2k times · Source

I have following 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

And following bootstrap.sh:

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

After running container and image with following lines:

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

I get following output:

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")

When I run bootstrap.sh locally on my ubuntu hostmachine everything works fine. What is wrong?

Answer

Rudziankoŭ picture Rudziankoŭ · Dec 14, 2017

I was able to fix it, my Dockerfile looks like this now:

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

bootstrap.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

And run it as following:

sudo docker build -t outyet .
sudo docker run --security-opt=seccomp:unconfined --net=host  --name test --rm outyet