All actions should be performed in the root directory of a Haskell project that uses stack.
The following lines should be present in the project's stack.yaml
file:
docker:
enable: true
Additionally, the BaseImage
and Dockerfile
files from this gist should also be present in the
project's root directory.
Note that both BaseImage
and Dockerfile
will have to be changed based on your needs:
- Any dependencies your project needs in order to build should be installed on the last line of
BaseImage
- All instances of
example
should instead refer to your project name in theDockerfile
To create the Alpine-based build container: docker build -f BaseImage -t <image_name> .
- where <image_name> is what you want your build image to be tagged as
- e.g.
docker build -f BaseImage -t alpine-ghc/base .
To build the binary: stack --docker-image=<image_name> install
- where <image_name> is what you tagged your build image as
- e.g.
stack --docker-image=alpine-ghc/base install
To build the deployment image: docker build -t <example> .
- where <example> is what you want your production image to be tagged as
- e.g.
docker build -t my-project .
To run the container locally: docker run -i -t <example>
- where <example> is what you tagged your production image as
- e.g.
docker run -i -t my-project
I think this should be a specific alpine version, for reproducibility. It's always possible that your Dockerfile will no longer work with a new release.