Home > Software engineering >  delve (dlv) in docker-compose: no such file or directory: unknown
delve (dlv) in docker-compose: no such file or directory: unknown

Time:01-13

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

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)

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/[email protected]

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

services:
  my-service:
    container_name: my-service
    build:
      context: .
      dockerfile: ${DOCKER_FILE:-Dockerfile} #            
  • Related