For a couple of reasons, you need to run this step during the "build" stage. That will leave the file in a known place where the "runtime" stage can COPY --from=build
it.
FROM fpco/stack-build:lts-14.20 as builder
...
RUN stack build
RUN cp $(stack exec which wai-crowd) /app
FROM alpine
COPY --from=builder /app/wai-crowd /usr/bin
EXPOSE 3000
CMD ["wai-crowd"]
When you start the second stage, it doesn't have any of the content from the first stage, so even ignoring the syntactic problems, the stack exec which ...
command wouldn't be able to see the build tree. Typically using a compiled language (like Haskell) you will want to avoid having the actual build tools in your final image, since they can be quite large; in my example I've used the lightweight alpine
image as the base for the final image, and so you also won't have the stack
command there.
The solution here is to leave any artifacts that you do want to copy into the final image in fixed paths. In my example I've reused the same /app
directory that the source is in but you can use pretty much any directory you want.