delve (dlv) in docker-compose: no such file or directory: un



我尝试运行go二进制与delve使用docker-compose,并得到一个错误:

ERROR: for nft-overseer  Cannot start service nft-overseer: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "dlv --listen=:${dlv_port} --headless=true --api-version=2 --accept-multiclient exec ./main": stat dlv --listen=:${dlv_port} --headless=true --api-version=2 --accept-multiclient exec ./main: no such file or directory: unknown

Dockerfile(简体)

FROM golang:1.19.1-alpine3.16 as builder
RUN apk --no-cache --update --upgrade add git alpine-sdk
ENV GO111MODULE on
ENV CGO_ENABLED 1
WORKDIR /app
COPY . .
RUN go mod download
RUN go build -gcflags "all=-N -l" ./cmd/main
FROM golang:1.19.1-alpine3.16
RUN apk --no-cache --update --upgrade add curl
RUN go install github.com/go-delve/delve/cmd/dlv@v1.20.1
ARG config_file
ARG dlv_port
WORKDIR /app
COPY configs/${config_file:-config.yaml} configs/config.yaml
COPY --from=0 /app/main .
CMD ["dlv --listen=${dlv_port} --headless=true --api-version=2 --accept-multiclient exec ./main"]

docker-compose。yml(简体)

services:
my-service:
container_name: my-service
build:
context: .
dockerfile: ${DOCKER_FILE:-Dockerfile} # 👈🏻 Dockerfile_dlv
args:
config_file: ${CONFIG:-config.yaml}
dlv_port: ${DLV_PORT}
ports:
- "10880:8080"
- "10881:8081"
- "10882:8082"
- 10883:${DLV_PORT:-2000}
healthcheck:
test: [ "CMD", "[[ ! -z ${DLV_PORT} ]] || curl", "-f", "http://localhost:8080/health" ]
interval: 10s
timeout: 5s
retries: 3
restart: always
CONFIG=$CONFIG DLV_PORT=2000 DOCKER_FILE=Dockerfile_dlv docker-compose up --build --force-recreate -d

容器中存在dlvmain

...
Step 23/28 : RUN pwd
2976 ---> Running in 1d8709c338c3
2977/app
2978Removing intermediate container 1d8709c338c3
2979 ---> 95514a03baea
2980Step 24/28 : RUN ls -l
2981 ---> Running in f65052ccf5e6
2982total 30536
2983drwxr-xr-x    2 root     root          4096 Jan 13 05:57 configs
2984-rwxr-xr-x    1 root     root      31261568 Jan 13 07:19 main
...
Step 25/28 : RUN dlv
2988 ---> Running in 15b54660a772
2989Delve is a source level debugger for Go programs.
2990Delve enables you to interact with your program by controlling the execution of the process,
2991evaluating variables, and providing information of thread / goroutine state, CPU register state and more.
2992The goal of this tool is to provide a simple yet powerful interface for debugging Go programs.
2993Pass flags to the program you are debugging using `--`, for example:
2994`dlv exec ./hello -- server --config conf/config.toml`
...

您需要将CMD的各个部分分开:

CMD ["dlv", "--listen=${dlv_port}", "--headless=true", "--api-version=2", "--accept-multiclient", "exec", "./main"]

现在它正在寻找一个文件" dllv——listen=${dlv_port}——headless=true——api-version=2——accept- multicclient exec ./main"

相关内容

最新更新