Reputation: 6180
My multi-stage build isn't finding the /assets/css
directory when it is time to copy it. What do I need to change?
Version 17.06.0-ce-mac17 (18432)
Channel: edge
4bb7a7dfa0
FROM ruby:2.4.1-slim
RUN mkdir /assets
VOLUME /assets
RUN gem install sass
ENTRYPOINT ["sass"]
Note the debugging commands I run on the first image cd /assets/css && ls && pwd
, the result is shown during the building phase.
# Compile Sass
FROM myimage/sass AS builder
COPY app/assets/sass /assets/sass
RUN sass --update --force --sourcemap=none --stop-on-error /assets/sass:/assets/css &&\
# sass directory isn't needed
rm -r assets/sass &&\
# debugging: check /assets/css exists inside the container
cd /assets/css && ls && pwd
FROM alpine:3.6
WORKDIR /app
RUN mkdir /app/logs
VOLUME ["/app/logs"]
COPY --from=builder /assets/css /app/assets/css
EXPOSE 80
CMD ["./bin/bash"]
Raw
docker build -t myimage:css .
Notice the output of cd /assets/css && ls && pwd
on step 3/11 showing the /assets/css
directory exists and it has a main.css
file inside
Step 1/11 : FROM myimage:sass AS builder
---> 7c6662186d55
Step 2/11 : COPY app/assets/sass /assets/sass
---> 76b5d86846b8
Removing intermediate container ee74d16617b4
Step 3/11 : RUN sass --update --force --sourcemap=none --stop-on-error /assets/sass:/assets/css && rm -r assets/sass && cd /assets/css && pwd
---> Running in 83dc591edc5c
directory /assets/css
write /assets/css/main.css
main.css
/assets/css
---> 3939f46fb355
Removing intermediate container 83dc591edc5c
Step 4/11 : FROM alpine:3.6
---> 7328f6f8b418
Step 5/11 : WORKDIR /app
---> 19ad596f9fc1
Removing intermediate container 790fac2040f1
Step 6/11 : RUN mkdir /app/logs
---> Running in cb66151a4694
---> 18d6c4970d04
Removing intermediate container cb66151a4694
Step 7/11 : VOLUME /app/logs
---> Running in b8a98a38a054
---> fa68603ccf30
Removing intermediate container b8a98a38a054
Step 8/11 : COPY --from=builder /assets/css /app/assets/css
COPY failed: stat /var/lib/docker/aufs/mnt/0ddcc250ed9c4eb1de46305e62cb2303274b027b2c9b0ddd09471fce3c3ed619/assets/css: no such file or directory
So why can't /assets/css
be copied into the final image? Why can't the Docker engine find it?
Upvotes: 4
Views: 2974
Reputation: 36913
This is the problem:
VOLUME /assets
Each build step is a new running container. Each new container will discard whatever drops in the unnamed volume.
Check that with:
RUN sass --update --force --sourcemap=none --stop-on-error /assets/sass:/assets/css &&\
# sass directory isn't needed
rm -r assets/sass
RUN cd /assets/css && ls && pwd
(A separate RUN)
Upvotes: 5