jekyll-docker icon indicating copy to clipboard operation
jekyll-docker copied to clipboard

"remove intermediate images" deletes build results

Open datenimperator opened this issue 4 years ago • 1 comments

I'm using the jekyll/jekyll image as a build stage in a multistage Dockerfile. When I use it like this, I'm running in an error:

# Jekyll build
#

FROM jekyll/jekyll:3.8.6 as builder

ENV TZ=Europe/Berlin \
    JEKYLL_ENV=production

RUN apk --no-cache add imagemagick

WORKDIR /srv/jekyll
COPY Gemfile* /srv/jekyll/
RUN bundle update

COPY _config.yml /srv/jekyll
COPY source /srv/jekyll/source
RUN jekyll build

# nginx runtime
#

FROM nginx:alpine

RUN rm -rf /usr/share/nginx/html/*

COPY --from=builder /srv/jekyll/_site/ /usr/share/nginx/html

The last RUN statement of jekyll will eventuall build the site and write it into /srv/jekyll/_site but afterwards the Docker log reads this image has been removed as intermediate. The subsequent COPY in the Nginx layer doesn't find the files.

However, if I create a separate directory (say: /site) along with appropriate permissions, things go well. This will work:

# Jekyll build
#

FROM jekyll/jekyll:3.8.6 as builder

ENV TZ=Europe/Berlin \
    JEKYLL_ENV=production

RUN apk --no-cache add imagemagick

RUN mkdir /site; \
    chown -R jekyll:jekyll /site

WORKDIR /site
COPY Gemfile* /site/
RUN bundle update

COPY _config.yml /site
COPY source /site/source
RUN jekyll build

# nginx runtime
#

FROM nginx:alpine

RUN rm -rf /usr/share/nginx/html/*

COPY --from=builder /site/_site/ /usr/share/nginx/html

I suspect this is because /srv/jekyll is declared as a volume, but I'm not sure. It does limit the usability of the image. Or am I using it wrong?

datenimperator avatar Jun 12 '20 08:06 datenimperator

I have the same problem. Webrick cannot be produced. How to add a server that can be produced. Is there an example of using dockerfile

mmm8955405 avatar Dec 30 '21 01:12 mmm8955405