I'm trying to convert my project to use multi-stage builds. However, the final step always fails with an error:

Step 11/13 : COPY --from=build /bin/grafana-server /bin/grafana-server
COPY failed: stat /var/lib/docker/overlay2/xxxx/merged/bin/grafana-server: no such file or directory

My Dockerfile looks like this:

FROM golang:latest AS build

ENV SRC_DIR=/go/src/github.com/grafana/grafana/


# Building of Grafana
  npm run build && \
  go run build.go setup && \
  go run build.go build

# Create final stage containing only required artifacts
FROM scratch
COPY --from=build /bin/grafana-server /bin/grafana-server


CMD ["./bin/grafana-server"]

The build.go build step will output artifacts to ./bin/ -- The error is pretty unhelpful other than telling me the files don't exist where I think they should exist.

My folder structure on my machine is:

--| ~/Documents/dev/grafana/src/grafana/grafana
--------| bin
------------| <grafan-server builds to here>

--------| deploy
------------| docker
----------------| Dockerfile

From ~/Documents/dev/grafana/src/grafana/grafana is where I issue: docker build -t grafana -f deploy/docker/Dockerfile .

  • Please add "RUN ls" to list the files in the location where you expect them to land and if they are there, please share the complete docker build output. – Peter Apr 28 '18 at 4:23
  • Copy from build, build being the alias you gave to the base image before any task... Remove the from and you'll be ok – Tensibai Apr 28 '18 at 18:39
  • @Tensibai - I think doing that defeats the benefit of multi-stage FROM scratch builds though? – MrDuk Apr 30 '18 at 14:47
  • 1
    My bad, misread the file and didn't saw the FROM scratch above the copy (but considering there's no reference to scratch anywhere in your file, it was easy to miss). Your problem comes from the absolute path used: /go/src/github.com/grafana/grafana/bin/grafana-server is not /bin/grafana-server, so: COPY --from=build /go/src/github.com/grafana/grafana/bin/grafana-server /bin/grafana-server should do. – Tensibai Apr 30 '18 at 14:56
  • Thanks, I'm now getting exec errors, presumably because I can't build with CGO_ENABLED=0 (not exactly sure why, but looks like some dependency issues, just get errors about not being able to load packages) – MrDuk Apr 30 '18 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.