Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell and Docker reasonable deployed image size?

I had tried building a PoC Happstack executable running in Google App Engine using this Dockerfile:

FROM ubuntu:14.04

ENV APP_ROOT=/usr/share/app

RUN apt-get update && apt-get install curl -y && curl -sSL https://get.haskellstack.org/ | sh

COPY . ${APP_ROOT}/
WORKDIR ${APP_ROOT}/
RUN stack setup
RUN stack build

EXPOSE 8000

ENTRYPOINT ["stack","exec","app-exe"]

This works and I was able to deploy, but the resulting image seems huge.

I think the image is about 450MB following the stack installation, about 1.8GB following stack setup, and about 3GB following stack build.

I think hundreds of MB seems reasonable, even up to a GB. Is there a different approach I should be taking, perhaps extracting the resulting executable to another image somehow to eliminate everything unnecessary at runtime?

like image 887
ryachza Avatar asked Mar 11 '18 16:03

ryachza


1 Answers

This is perfect for docker multi stage builds:

https://docs.docker.com/develop/develop-images/multistage-build/

You can apply as follows:

FROM ubuntu:14.04 as mybuild

ENV APP_ROOT=/usr/share/app

RUN apt-get update && apt-get install curl -y && curl -sSL https://get.haskellstack.org/ | sh

COPY . ${APP_ROOT}/
WORKDIR ${APP_ROOT}/
RUN stack setup
RUN stack build

FROM ubuntu:14.04

COPY --from=mybuild /path/to/app-exe /dest/app-exe #edit this line accordingly

EXPOSE 8000

ENTRYPOINT ["stack","exec","app-exe"]

Everything before the second FROM is not included in the final image, except what you copy with COPY --from.

like image 117
Robert Avatar answered Sep 24 '22 20:09

Robert