在docker-compose中查找(dlv):没有这样的文件或目录:未知

huangapple go评论97阅读模式
英文:

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

问题

我尝试使用docker-compose运行带有delvego二进制文件,并且遇到了一个错误:

  1. 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(简化版):

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

docker-compose.yml(简化版):

  1. services:
  2. my-service:
  3. container_name: my-service
  4. build:
  5. context: .
  6. dockerfile: ${DOCKER_FILE:-Dockerfile} # 使用Dockerfile_dlv
  7. args:
  8. config_file: ${CONFIG:-config.yaml}
  9. dlv_port: ${DLV_PORT}
  10. ports:
  11. - "10880:8080"
  12. - "10881:8081"
  13. - "10882:8082"
  14. - 10883:${DLV_PORT:-2000}
  15. healthcheck:
  16. test: ["CMD", "[[ ! -z ${DLV_PORT} ]] || curl", "-f", "http://localhost:8080/health"]
  17. interval: 10s
  18. timeout: 5s
  19. retries: 3
  20. restart: always

运行命令:

  1. CONFIG=$CONFIG DLV_PORT=2000 DOCKER_FILE=Dockerfile_dlv docker-compose up --build --force-recreate -d

在容器中存在dlvmain文件:

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

I try to run go binary with delve use docker-compose and get an error:

  1. 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 (simplified)

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

docker-compose.yml (simplified)

  1. services:
  2. my-service:
  3. container_name: my-service
  4. build:
  5. context: .
  6. dockerfile: ${DOCKER_FILE:-Dockerfile} # 👈🏻 Dockerfile_dlv
  7. args:
  8. config_file: ${CONFIG:-config.yaml}
  9. dlv_port: ${DLV_PORT}
  10. ports:
  11. - "10880:8080"
  12. - "10881:8081"
  13. - "10882:8082"
  14. - 10883:${DLV_PORT:-2000}
  15. healthcheck:
  16. test: [ "CMD", "[[ ! -z ${DLV_PORT} ]] || curl", "-f", "http://localhost:8080/health" ]
  17. interval: 10s
  18. timeout: 5s
  19. retries: 3
  20. restart: always
  1. CONFIG=$CONFIG DLV_PORT=2000 DOCKER_FILE=Dockerfile_dlv docker-compose up --build --force-recreate -d

dlv and main exists in container

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

答案1

得分: 2

你需要将 CMD 的部分分开:

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

目前它正在寻找一个名为 "dlv --listen=${dlv_port} --headless=true --api-version=2 --accept-multiclient exec ./main" 的文件。

英文:

You need to separate the parts of the CMD:

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

Right now it's looking for a file "dlv --listen=${dlv_port} --headless=true --api-version=2 --accept-multiclient exec ./main".

huangapple
  • 本文由 发表于 2023年1月13日 15:37:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75106112.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定