Skip to content

Instantly share code, notes, and snippets.

@TimWSpence
Created July 15, 2019 15:31
Show Gist options
  • Save TimWSpence/269ab6943fbbaaf4b66374364f0051cd to your computer and use it in GitHub Desktop.
Save TimWSpence/269ab6943fbbaaf4b66374364f0051cd to your computer and use it in GitHub Desktop.
A minimal Docker multi-stage build for a Haskell stack application
# Loosely based on https://www.fpcomplete.com/blog/2017/12/building-haskell-apps-with-docker
FROM fpco/stack-build:lts-13.27 as build
RUN mkdir /opt/build
WORKDIR /opt/build
# GHC dynamically links its compilation targets to lib gmp
RUN apt-get update \
&& apt-get download libgmp10
RUN mv libgmp*.deb libgmp.deb
COPY . /opt/build
RUN stack build --system-ghc
RUN mv "$(stack path --local-install-root --system-ghc)/bin" /opt/build/bin
# Base image for stack build so compiled artifact from previous
# stage should run
FROM ubuntu:16.04
RUN mkdir -p /opt/executable
WORKDIR /opt/executable
# Install lib gmp
COPY --from=build /opt/build/libgmp.deb /tmp
RUN dpkg -i /tmp/libgmp.deb && rm /tmp/libgmp.deb
COPY --from=build /opt/build/bin .
EXPOSE 8080
CMD ["/opt/executable/run", "8080"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment