Multistage Docker Build COPY fails, file not found

Viewed 2431

I have a multistage Dockerfile for a small Jekyll site.

Dockerfile:

FROM jekyll/minimal AS build

COPY . /srv/jekyll

RUN jekyll build

FROM pierrezemb/gostatic

COPY --from=build /srv/jekyll/_site /srv/http

Docker fails at the last stage, with the following error:

Step 5/5 : COPY --from=build /srv/jekyll/_site /srv/http
COPY failed: stat /var/lib/docker/overlay2/e6b407b63b9578dd7ae4ccba968fff3f4e28e35e50e887c09319b32ccd548356/merged/srv/jekyll/_site: no such file or directory

If I remove the second FROM and exec into the build container, I can see the files exist in /srv/jekyll/_site.

2 Answers

I have taken your dockerfile, and followed the jekyll quickstart tutorial. While I cannot actually build your dockerfile since you have chosen the jekyll/minimal base image, changing it to jekyll/builder makes the entire process work with a minor change. I am building in the /tmp folder instead.

Truncated...
Fetching minima 2.5.0
Installing minima 2.5.0
Bundle complete! 4 Gemfile dependencies, 29 gems now installed.
Bundled gems are installed into `/usr/local/bundle`
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-linux-musl]
Configuration file: /tmp/_config.yml
            Source: /tmp
       Destination: /tmp/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
       Jekyll Feed: Generating feed for posts
                    done in 0.507 seconds.
 Auto-regeneration: disabled. Use --watch to enable.
Removing intermediate container 10159e9e7776
 ---> cab3989600a7
Step 5/6 : FROM pierrezemb/gostatic
 ---> bbc54b2880be
Step 6/6 : COPY --from=build /tmp/_site /srv/http
 ---> 860f5db9d0f3
Successfully built 860f5db9d0f3
Successfully tagged test:latest

If you send me a GitHub link to your code I can have a look, perhaps you have made a typo somewhere ?

( Here is my dockerfile that works with the tutorial from jekyll )

FROM jekyll/builder as build
WORKDIR /tmp
COPY . /tmp

RUN jekyll build

FROM pierrezemb/gostatic

COPY --from=build /tmp/_site /srv/http

It looks like /srv/jekyll is defined as a volume in your parent image. If you create a container from that image, the directory won't be from the image but from a temporary volume created, resulting in unexpected behaviors. During a build, if you try to change the contents of that directory with a RUN command, those changes will all be lost at the end of that run command as the anonymous volume is cleaned.

I'd recommend getting the upstream creator of that image to remove the VOLUME definition from their Dockerfile, or forking the repo and building your own without that volume. You can always define a volume at run time without the volume defined in the image, but once it gets defined in the image, your ability to work with the directory will be impacted by that volume.

Related