S
S
sudo rm -rf /2020-10-09 11:56:09
Haskell
sudo rm -rf /, 2020-10-09 11:56:09

Is it possible to save an intermediate image to a container and use it for other projects?

I write in Haskell and use Stack.
In order to start compiling the code, you need to have the stack installed and write stack setup. This downloads the compiler and allows you to start building.
If I want to wrap my applications in docker. Then I have to download the stack, initialize it, and, as a result, build the application.
Because of this, an application that, after assembly, takes a couple of megabytes at most, begins to weigh 6 gigs.

Is it possible somehow to create a container with pre-installed stackand use it to build containers?
To be able to remove unnecessary tools after assembly and leave only the application itself in the application image to run.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zohan1993, 2020-10-09
@zohan1993

to minify an image with a
multistage-build
application step 1
install all the necessary tools and dependencies to compile the application
compile the application
step 2
install all the dependencies necessary for the application to work
copy the finished application to a new image

W
wiz, 2020-11-04
@wiz

Firstly, stack has a native way of building via docker: https://docs.haskellstack.org/en/stable/docker_int...
If you want to build docker images with some pre-built dependencies, you can take the image used in stack, build there are project dependencies and already use the result for assembly in docker.
If you need to build an application in the docker, and then deploy only the binary, then this is already a multistage.
Well, this is about an average recipe, because there are a lot of variations:

FROM fpco/stack-build:lts-16.20 as build

WORKDIR /opt/source
RUN stack --resolver=lts-16.20 --system-ghc install example-exe

FROM fpco/stack-run
WORKDIR /opt/dist
COPY --from=build-env /home/user/.local/bin/example-exe .

CMD ./example-exe

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question