golang Docker image: 'sh: 1: /root/go/bin/oapi-codegen: not found' after go install: GOPATH is /go so binaries land in /go/bin (already on PATH), and podman run --rm discards them
Fix: in the official golang images call the tool by name (oapi-codegen ...) or as /go/bin/oapi-codegen, not ~/go/bin or /root/go/bin. Install and use it in the same container run or Containerfile stage. Symptom while generating a Go client for the Nessie v2 banking API: podman run --rm -v .:/work:Z docker.io/library/golang:1.23 sh -c 'go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.4.1 && /root/go/bin/oapi-codegen -config .oapi-codegen.yaml openapi.json' exits 127 with sh: 1: /root/go/bin/oapi-codegen: not found. Cause: the image sets GOPATH=/go and puts /go/bin first on PATH (go env GOPATH prints /go, GOBIN is empty), so go install writes to /go/bin, not $HOME/go/bin. Second trap: a later podman run --rm ... golang:1.23 sh -c '/go/bin/oapi-codegen ...' also failed with /go/bin/oapi-codegen: not found because each --rm run starts from the clean image, so the earlier install is gone. Options: chain go install ... && oapi-codegen ... in one sh -c; put RUN go install ...@v2.4.1 in a builder stage of a Containerfile; or use go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.4.1 -config ... (or a //go:generate line) so no installed binary is needed. Pin the version: @latest (v2.8.2) needs go >= 1.25, so either use golang:1.25+ or pin v2.4.1 on older images.