Home > Enterprise >  Dockerfile can't find output on linux
Dockerfile can't find output on linux

Time:03-21

I have the following Dockerfile

ARG JEKYLL_VERSION=4
FROM jekyll/jekyll:$JEKYLL_VERSION as BUILD

COPY --chown=jekyll:jekyll . /srv/jekyll
RUN ls -lah /srv/jekyll

RUN jekyll build
RUN ls /srv/jekyll/_site/

FROM nginxinc/nginx-unprivileged:alpine
ADD build/nginx-site.conf /etc/nginx/conf.d/default.conf

COPY --chown=101:101 --from=BUILD /srv/jekyll/_site/ /var/www

Which does build perfectly locally, but not on the Linux Jenkins Buildslave:

Bundle complete! 1 Gemfile dependency, 28 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux-musl]
Configuration file: /srv/jekyll/_config.yml
            Source: /srv/jekyll
       Destination: /srv/jekyll/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
                    done in 0.186 seconds.
 Auto-regeneration: disabled. Use --watch to enable.
Removing intermediate container 2b064db0ccaa
 ---> 1e19e78f593a
Step 6/9 : RUN ls /srv/jekyll/_site/
 ---> Running in 194d35c3f691
[91mls: /srv/jekyll/_site/: No such file or directory
[0mThe command '/bin/sh -c ls /srv/jekyll/_site/' returned a non-zero code: 1

Changing RUN jekyll build to RUN jekyll build && ls /srv/jekyll/_site/ lists the jekyll output as expected. Why is the output of the jekyll build not stored? If I remove the ls command, the output can't be found in the later stage. Any hints?

CodePudding user response:

That happens because the image declares that directory as a VOLUME. This is probably a bug and I'd suggest reporting it as a GitHub issue; it won't affect any of the documented uses of the image to remove that line.

At the end of the day Jekyll is just a Ruby gem (library). So while that image installs a lot of things, for your use it might be enough to start from a ruby image, install the gem, and use it:

FROM ruby:3.1
RUN gem install jekyll
WORKDIR /site
COPY . .
RUN jekyll build

If your directory tree contains a Ruby Gemfile and Gemfile.lock, you could also COPY those into the image and RUN bundle install instead.

Alternatively, since Jekyll is a static site generator, you should get the same results if you build the site on the host or in a container, and another good path could be to install Ruby and Jekyll on your host (maybe in an rbenv gemset) and then COPY the site from the host into the Nginx image; skip the first stage entirely.

  • Related