问题
I'm building a docker image from a Haskell application, I'm executing stack build
from within the container.
Because stack build
is starting from a 'fresh/vanilla' docker image - all the libraries need to be installed/pulled.
Is there a way I can pre-install these library dependencies? For the end goal of reducing the docker image build time (stack build
). I'd also like to be able to later on 'add' an additional dependency without having to once again stack build
everything over from start.
A possible solution:
I tried a series of:
RUN stack install --only-dependencies --resolver="lts-14.27" aeson
RUN stack install --only-dependencies --resolver="lts-14.27" aeson-pretty
RUN stack install --only-dependencies --resolver="lts-14.27" ansi-terminal
RUN stack install --only-dependencies --resolver="lts-14.27" ansi-wl-pprint
RUN stack install --only-dependencies --resolver="lts-14.27" appar
RUN stack install --only-dependencies --resolver="lts-14.27" array
RUN stack install --only-dependencies --resolver="lts-14.27" asn1-encoding
RUN stack install --only-dependencies --resolver="lts-14.27" asn1-parse
RUN stack install --only-dependencies --resolver="lts-14.27" asn1-types
RUN stack install --only-dependencies --resolver="lts-14.27" async
RUN stack install --only-dependencies --resolver="lts-14.27" attoparsec
RUN stack install --only-dependencies --resolver="lts-14.27" authenticate-oauth
RUN stack install --only-dependencies --resolver="lts-14.27" auto-update
RUN stack install --only-dependencies --resolver="lts-14.27" base
RUN stack install --only-dependencies --resolver="lts-14.27" base-compat
RUN stack install --only-dependencies --resolver="lts-14.27" base-orphans
RUN stack install --only-dependencies --resolver="lts-14.27" base16-bytestring
However this has a side effect of also installing any executable related to this library. And the resulting Docker image is enormous - 67GB:
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> d2a95ef3622d 11 seconds ago 67GB
回答1:
This seems to do it:
stack build --only-dependencies
来源:https://stackoverflow.com/questions/54508207/how-to-pre-install-stack-dependencies-to-reduce-stack-build-time