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

<pre><code>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
</code></pre>

<p>My Dockerfile looks like this:</p>

<pre><code>FROM golang:latest AS build

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

COPY . $SRC_DIR
WORKDIR $SRC_DIR

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

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

EXPOSE 3001

CMD ["./bin/grafana-server"]
</code></pre>

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

<p>My folder structure on my machine is:</p>

<pre><code>--| ~/Documents/dev/grafana/src/grafana/grafana
--------| bin
------------| &lt;grafan-server builds to here&gt;

--------| deploy
------------| docker
----------------| Dockerfile
</code></pre>

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

CC BY-SA 3.0
2018-04-28T04:23:13.087Z
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.
Ta Mu
CC BY-SA 3.0
2018-04-28T18:39:13.350Z
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
CC BY-SA 3.0
2018-04-30T14:47:58.313Z
@Tensibai - I think doing that defeats the benefit of multi-stage `FROM scratch` builds though?
MrDuk
CC BY-SA 3.0
2018-04-30T14:56:26.940Z
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
CC BY-SA 3.0
2018-04-30T15:25:32.387Z
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
CC BY-SA 4.0
2018-09-29T14:04:21.277Z
I got the same error too :-(
zx1986
CC BY-SA 4.0
2019-10-25T10:51:24.337Z
The problem may have to do with a `VOLUME` in the `golang` base image: https://stackoverflow.com/a/54081885/539599, https://stackoverflow.com/a/45109320/539599
Raphael
CC BY-SA 4.0
2019-12-19T14:07:43.737Z
@MrDuk could you post an answer?
030
CC BY-SA 4.0
2019-12-23T10:59:24.260Z
@MrDuk `Step 6/10 : RUN   npm run build &&   go run build.go setup &&   go run build.go build
 ---> Running in d08c6bc14193
/bin/sh: 1: npm: not found` Please fix the issues in the Dockerfile.
030
<docker>
Issues with COPY when using multistage Dockerfile builds -- no such file or directory
MrDuk
# Issues with COPY when using multistage Dockerfile builds -- no such file or directory

(Asked by: username_0 on 2018-04-27)

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/
ENV GIT_SSL_NO_VERIFY=1

COPY . $SRC_DIR
WORKDIR $SRC_DIR

# Building of Grafana
RUN \
  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

EXPOSE 3001

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
------------| 

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

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

**Tags:** docker

> **Comments:**
> **username_1**: 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.  
> **username_2**: Copy from build, build being the alias you gave to the base image before any task... Remove the from and you'll be ok  
> **username_0**: @username_2 - I think doing that defeats the benefit of multi-stage `FROM scratch` builds though?  
> **username_2**: 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.  
> **username_0**: 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)  
> **username_3**: I got the same error too :-(  
> **username_4**: The problem may have to do with a `VOLUME` in the `golang` base image: https://stackoverflow.com/a/54081885/539599, https://stackoverflow.com/a/45109320/539599  
> **username_5**: @username_0 could you post an answer?  
> **username_5**: @username_0 `Step 6/10 : RUN   npm run build &&   go run build.go setup &&   go run build.go build  ---> Running in d08c6bc14193 /bin/sh: 1: npm: not found` Please fix the issues in the Dockerfile.  

---

## 0 answers

